drop separate scalar module, implement on top of Vec
MODIFY
src/hub/manual/core.rs
src/hub/manual/core.rs
pub use self::mat::*;
pub use self::point::*;
pub use self::rect::*;
-pub use self::scalar::*;
pub use self::size::*;
pub use self::vec::*;
@@ -24,7 +23,6 @@ macro_rules! valid_types {
mod mat;
mod point;
mod rect;
-mod scalar;
mod size;
mod vec;

DELETE
src/hub/manual/core/scalar.rs
-use std::ops::{Deref, DerefMut};
-
-valid_types!(ValidScalarType, f64);
-
-#[repr(C)]
-#[derive(Copy, Clone, Debug, PartialEq)]
-pub struct Scalar_<T: ValidScalarType>(pub [T; 4]);
-
-impl<T: ValidScalarType> Scalar_<T> {
- pub fn new(v0: T, v1: T, v2: T, v3: T) -> Self {
- Self([v0, v1, v2, v3])
- }
-}
-
-impl<T: ValidScalarType + Copy> Scalar_<T> {
- pub fn all(v0: T) -> Self {
- Self([v0; 4])
- }
-}
-
-impl<T: ValidScalarType> Deref for Scalar_<T> {
- type Target = [T; 4];
-
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-
-impl<T: ValidScalarType> DerefMut for Scalar_<T> {
- fn deref_mut(&mut self) -> &mut Self::Target {
- &mut self.0
- }
-}
-
-impl<T: ValidScalarType + Default + Copy> Default for Scalar_<T> {
- fn default() -> Self {
- Self([Default::default(); 4])
- }
-}

MODIFY
src/hub/manual/core/vec.rs
src/hub/manual/core/vec.rs
use std::ops::{Deref, DerefMut};
-valid_types!(ValidVecType, u8, i16, u16, i32, f32, f64);
+pub use self::{scalar::ValidScalarType, vec::ValidVecType};
+
+// additional modules needed because valid_types! introduces named private module
+mod vec {
+ valid_types!(ValidVecType, i8, u8, i16, u16, i32, f32, f64);
+}
+
+mod scalar {
+ valid_types!(ValidScalarType, f64);
+}
macro_rules! vec_impl {
- ($type: ident, $count: expr) => {
+ ($type: ident, $count: expr, $type_trait: ident) => {
#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq)]
- pub struct $type<T: ValidVecType>(pub [T; $count]);
+ pub struct $type<T: $type_trait>(pub [T; $count]);
- impl<T: ValidVecType> From<[T; $count]> for $type<T> {
+ impl<T: $type_trait> From<[T; $count]> for $type<T> {
fn from(s: [T; $count]) -> $type<T> {
$type::<T>(s)
}
}
- impl<T: ValidVecType> Deref for $type<T> {
+ impl<T: $type_trait> $type<T> {
+ pub fn all(v0: T) -> Self {
+ Self([v0; $count])
+ }
+ }
+
+ impl<T: $type_trait> Deref for $type<T> {
type Target = [T; $count];
fn deref(&self) -> &Self::Target {
@@ -22,13 +37,13 @@ macro_rules! vec_impl {
}
}
- impl<T: ValidVecType> DerefMut for $type<T> {
+ impl<T: $type_trait> DerefMut for $type<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
- impl<T: ValidVecType + Default + Copy> Default for $type<T> {
+ impl<T: $type_trait + Default> Default for $type<T> {
fn default() -> Self {
Self([Default::default(); $count])
}
@@ -36,8 +51,15 @@ macro_rules! vec_impl {
};
}
-vec_impl!(Vec2, 2);
-vec_impl!(Vec3, 3);
-vec_impl!(Vec4, 4);
-vec_impl!(Vec6, 6);
-vec_impl!(Vec8, 8);
+vec_impl!(Vec2, 2, ValidVecType);
+vec_impl!(Vec3, 3, ValidVecType);
+vec_impl!(Vec4, 4, ValidVecType);
+vec_impl!(Vec6, 6, ValidVecType);
+vec_impl!(Vec8, 8, ValidVecType);
+vec_impl!(Scalar_, 4, ValidScalarType);
+
+impl<T: ValidScalarType> Scalar_<T> {
+ pub fn new(v0: T, v1: T, v2: T, v3: T) -> Self {
+ Self([v0, v1, v2, v3])
+ }
+}

drop separate scalar module, implement on top of Vec