Skip to content

Commit

Permalink
Derive UniformArray on all types
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsided committed Jul 13, 2024
1 parent 5db0766 commit 964867e
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 286 deletions.
37 changes: 2 additions & 35 deletions src/accelerometer_noise.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::impl_standard_traits;
use core::fmt::{Debug, Formatter};
use core::ops::Mul;
use uniform_array_derive::UniformArray;

#[derive(UniformArray)]
#[cfg_attr(test, ensure_uniform_type::ensure_uniform_type)]
#[repr(C)]
pub struct AccelerometerNoise<T> {
Expand All @@ -19,13 +21,6 @@ impl<T> AccelerometerNoise<T> {
pub const fn new(x: T, y: T, z: T) -> Self {
Self { x, y, z }
}

/// Returns the length of the [`AccelerometerNoise`] vector.
#[inline(always)]
#[allow(clippy::len_without_is_empty)]
pub const fn len(&self) -> usize {
3
}
}

impl<T> Default for AccelerometerNoise<T>
Expand Down Expand Up @@ -79,34 +74,6 @@ where
}
}

#[cfg(not(feature = "unsafe"))]
impl<T> core::ops::Index<usize> for AccelerometerNoise<T> {
type Output = T;

#[inline(always)]
fn index(&self, index: usize) -> &Self::Output {
match index {
0 => &self.x,
1 => &self.y,
2 => &self.z,
_ => panic!("Index out of bounds"),
}
}
}

#[cfg(not(feature = "unsafe"))]
impl<T> core::ops::IndexMut<usize> for AccelerometerNoise<T> {
#[inline(always)]
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
match index {
0 => &mut self.x,
1 => &mut self.y,
2 => &mut self.z,
_ => panic!("Index out of bounds"),
}
}
}

impl_standard_traits!(AccelerometerNoise, T);

#[cfg(test)]
Expand Down
37 changes: 2 additions & 35 deletions src/accelerometer_reading.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::impl_standard_traits;
use core::fmt::{Debug, Formatter};
use core::ops::Mul;
use uniform_array_derive::UniformArray;

#[derive(UniformArray)]
#[cfg_attr(test, ensure_uniform_type::ensure_uniform_type)]
#[repr(C)]
pub struct AccelerometerReading<T> {
Expand Down Expand Up @@ -35,13 +37,6 @@ impl<T> AccelerometerReading<T> {
z: coordinate.z(),
}
}

/// Returns the length of the [`AccelerometerReading`] vector.
#[inline(always)]
#[allow(clippy::len_without_is_empty)]
pub const fn len(&self) -> usize {
3
}
}

impl<T> Default for AccelerometerReading<T>
Expand Down Expand Up @@ -107,34 +102,6 @@ where
}
}

#[cfg(not(feature = "unsafe"))]
impl<T> core::ops::Index<usize> for AccelerometerReading<T> {
type Output = T;

#[inline(always)]
fn index(&self, index: usize) -> &Self::Output {
match index {
0 => &self.x,
1 => &self.y,
2 => &self.z,
_ => panic!("Index out of bounds"),
}
}
}

#[cfg(not(feature = "unsafe"))]
impl<T> core::ops::IndexMut<usize> for AccelerometerReading<T> {
#[inline(always)]
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
match index {
0 => &mut self.x,
1 => &mut self.y,
2 => &mut self.z,
_ => panic!("Index out of bounds"),
}
}
}

impl_standard_traits!(AccelerometerReading, T);

#[cfg(test)]
Expand Down
40 changes: 2 additions & 38 deletions src/euler_angles.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::impl_standard_traits;
use core::fmt::{Debug, Formatter};
use uniform_array_derive::UniformArray;

#[derive(UniformArray)]
#[cfg_attr(test, ensure_uniform_type::ensure_uniform_type)]
#[repr(C)]
pub struct EulerAngles<T> {
Expand All @@ -22,14 +24,6 @@ impl<T> EulerAngles<T> {
yaw_psi,
}
}

/// Returns the length of the [`EulerAngles`] vector.
#[inline(always)]
#[allow(unused)]
#[allow(clippy::len_without_is_empty)]
pub const fn len(&self) -> usize {
3
}
}

impl<T> Default for EulerAngles<T>
Expand Down Expand Up @@ -68,36 +62,6 @@ where
}
}

#[cfg_attr(docsrs, doc(cfg(not(feature = "unsafe"))))]
#[cfg(not(feature = "unsafe"))]
impl<T> core::ops::Index<usize> for EulerAngles<T> {
type Output = T;

#[inline(always)]
fn index(&self, index: usize) -> &Self::Output {
match index {
0 => &self.roll_phi,
1 => &self.pitch_theta,
2 => &self.yaw_psi,
_ => panic!("Index out of bounds"),
}
}
}

#[cfg_attr(docsrs, doc(cfg(not(feature = "unsafe"))))]
#[cfg(not(feature = "unsafe"))]
impl<T> core::ops::IndexMut<usize> for EulerAngles<T> {
#[inline(always)]
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
match index {
0 => &mut self.roll_phi,
1 => &mut self.pitch_theta,
2 => &mut self.yaw_psi,
_ => panic!("Index out of bounds"),
}
}
}

impl_standard_traits!(EulerAngles, T);

#[cfg(test)]
Expand Down
38 changes: 2 additions & 36 deletions src/gyroscope_bias.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::impl_standard_traits;
use core::fmt::{Debug, Formatter};
use core::ops::{Mul, Sub};
use uniform_array_derive::UniformArray;

#[derive(UniformArray)]
#[cfg_attr(test, ensure_uniform_type::ensure_uniform_type)]
#[repr(C)]
pub struct GyroscopeBias<T> {
Expand All @@ -23,14 +25,6 @@ impl<T> GyroscopeBias<T> {
omega_z,
}
}

/// Returns the length of the [`GyroscopeBias`] vector.
#[inline(always)]
#[allow(unused)]
#[allow(clippy::len_without_is_empty)]
pub const fn len(&self) -> usize {
3
}
}

impl<T> Default for GyroscopeBias<T>
Expand Down Expand Up @@ -99,34 +93,6 @@ where
}
}

#[cfg(not(feature = "unsafe"))]
impl<T> core::ops::Index<usize> for GyroscopeBias<T> {
type Output = T;

#[inline(always)]
fn index(&self, index: usize) -> &Self::Output {
match index {
0 => &self.omega_x,
1 => &self.omega_y,
2 => &self.omega_z,
_ => panic!("Index out of bounds"),
}
}
}

#[cfg(not(feature = "unsafe"))]
impl<T> core::ops::IndexMut<usize> for GyroscopeBias<T> {
#[inline(always)]
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
match index {
0 => &mut self.omega_x,
1 => &mut self.omega_y,
2 => &mut self.omega_z,
_ => panic!("Index out of bounds"),
}
}
}

impl_standard_traits!(GyroscopeBias, T);

#[cfg(test)]
Expand Down
37 changes: 2 additions & 35 deletions src/gyroscope_noise.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::impl_standard_traits;
use core::fmt::{Debug, Formatter};
use core::ops::Mul;
use uniform_array_derive::UniformArray;

#[derive(UniformArray)]
#[cfg_attr(test, ensure_uniform_type::ensure_uniform_type)]
#[repr(C)]
pub struct GyroscopeNoise<T> {
Expand All @@ -19,13 +21,6 @@ impl<T> GyroscopeNoise<T> {
pub const fn new(x: T, y: T, z: T) -> Self {
Self { x, y, z }
}

/// Returns the length of the [`GyroscopeNoise`] vector.
#[inline(always)]
#[allow(clippy::len_without_is_empty)]
pub const fn len(&self) -> usize {
3
}
}

impl<T> Default for GyroscopeNoise<T>
Expand Down Expand Up @@ -79,34 +74,6 @@ where
}
}

#[cfg(not(feature = "unsafe"))]
impl<T> core::ops::Index<usize> for GyroscopeNoise<T> {
type Output = T;

#[inline(always)]
fn index(&self, index: usize) -> &Self::Output {
match index {
0 => &self.x,
1 => &self.y,
2 => &self.z,
_ => panic!("Index out of bounds"),
}
}
}

#[cfg(not(feature = "unsafe"))]
impl<T> core::ops::IndexMut<usize> for GyroscopeNoise<T> {
#[inline(always)]
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
match index {
0 => &mut self.x,
1 => &mut self.y,
2 => &mut self.z,
_ => panic!("Index out of bounds"),
}
}
}

impl_standard_traits!(GyroscopeNoise, T);

#[cfg(test)]
Expand Down
38 changes: 2 additions & 36 deletions src/gyroscope_reading.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::impl_standard_traits;
use core::fmt::{Debug, Formatter};
use core::ops::{Mul, Sub};
use uniform_array_derive::UniformArray;

#[derive(UniformArray)]
#[cfg_attr(test, ensure_uniform_type::ensure_uniform_type)]
#[repr(C)]
pub struct GyroscopeReading<T> {
Expand Down Expand Up @@ -39,14 +41,6 @@ impl<T> GyroscopeReading<T> {
omega_z: coordinate.z(),
}
}

/// Returns the length of the [`GyroscopeReading`] vector.
#[inline(always)]
#[allow(unused)]
#[allow(clippy::len_without_is_empty)]
pub const fn len(&self) -> usize {
3
}
}

impl<T> Default for GyroscopeReading<T>
Expand Down Expand Up @@ -127,34 +121,6 @@ where
}
}

#[cfg(not(feature = "unsafe"))]
impl<T> core::ops::Index<usize> for GyroscopeReading<T> {
type Output = T;

#[inline(always)]
fn index(&self, index: usize) -> &Self::Output {
match index {
0 => &self.omega_x,
1 => &self.omega_y,
2 => &self.omega_z,
_ => panic!("Index out of bounds"),
}
}
}

#[cfg(not(feature = "unsafe"))]
impl<T> core::ops::IndexMut<usize> for GyroscopeReading<T> {
#[inline(always)]
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
match index {
0 => &mut self.omega_x,
1 => &mut self.omega_y,
2 => &mut self.omega_z,
_ => panic!("Index out of bounds"),
}
}
}

impl_standard_traits!(GyroscopeReading, T);

#[cfg(test)]
Expand Down
Loading

0 comments on commit 964867e

Please sign in to comment.