From 98d720816d4a607ce8343fdaa83bfcabbdb19b12 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Thu, 22 Mar 2018 01:07:06 -0400 Subject: [PATCH] Moved the Bounded trait to the Weave library. --- Cargo.toml | 3 ++ src/bounded.rs | 102 ------------------------------------------------- src/lib.rs | 5 +-- src/matrix.rs | 4 +- src/number.rs | 3 +- 5 files changed, 9 insertions(+), 108 deletions(-) delete mode 100644 src/bounded.rs diff --git a/Cargo.toml b/Cargo.toml index 149cb98..114f41f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,9 @@ documentation = "" keywords = ["sigils"] +[dependencies.weave] +git = "ssh://git@gitlab.com/CyberMages/Core/weave" + [dependencies.binding] git = "ssh://git@gitlab.com/CyberMages/Core/binding" diff --git a/src/bounded.rs b/src/bounded.rs deleted file mode 100644 index 547b946..0000000 --- a/src/bounded.rs +++ /dev/null @@ -1,102 +0,0 @@ -use std::{u8, u16, u32, u64, usize, i8, i16, i32, i64, isize, f32, f64}; - - -/// Primitive types that have upper and lower bounds. -pub trait Bounded -{ - /// The minimum value for this type. - const MIN: Self; - - /// The maximum value for this type. - const MAX: Self; -} - - -/// A macro for making implementation of -/// the Bounded trait easier. -macro_rules! bounded_trait_impl -{ - ($T: ty, $minVal: expr, $maxVal: expr) => - { - impl Bounded for $T - { - const MIN: $T = $minVal; - - const MAX: $T = $maxVal; - } - } -} - - -// Implement the Bounded for all the primitive types. -bounded_trait_impl!(u8, 0u8, !0u8); -bounded_trait_impl!(u16, 0u16, !0u16); -bounded_trait_impl!(u32, 0u32, !0u32); -bounded_trait_impl!(u64, 0u64, !0u64); -bounded_trait_impl!(usize, 0usize, !0usize); - -bounded_trait_impl!(i8, (!0i8 ^ (!0u8 >> 1u8) as i8), - !(!0i8 ^ (!0u8 >> 1u8) as i8)); -bounded_trait_impl!(i16, (!0i16 ^ (!0u16 >> 1u16) as i16), - !(!0i16 ^ (!0u16 >> 1u16) as i16)); -bounded_trait_impl!(i32, (!0i32 ^ (!0u32 >> 1u32) as i32), - !(!0i32 ^ (!0u32 >> 1u32) as i32)); -bounded_trait_impl!(i64, (!0i64 ^ (!0u64 >> 1u64) as i64), - !(!0i64 ^ (!0u64 >> 1u64) as i64)); -bounded_trait_impl!(isize, (!0isize ^ (!0usize >> 1usize) as isize), - !(!0isize ^ (!0usize >> 1usize) as isize)); - -bounded_trait_impl!(f32, -3.40282347e+38f32, 3.40282347e+38f32); -bounded_trait_impl!(f64, -1.7976931348623157e+308f64, - 1.7976931348623157e+308f64); - - - -#[cfg(test)] -mod tests -{ - macro_rules! bounds_test - { - ($T: ident, $func_name: ident, $minVal: expr, $maxVal: expr) => - { - #[test] - fn $func_name() - { - use bounded::Bounded; - - - - assert_eq!($T::MIN, $minVal); - assert_eq!($T::MAX, $maxVal); - } - } - } - - bounds_test!(u8, min_max_u8, 0u8, !0u8); - bounds_test!(u16, min_max_u16, 0u16, !0u16); - bounds_test!(u32, min_max_u32, 0u32, !0u32); - bounds_test!(u64, min_max_u64, 0u64, !0u64); - bounds_test!(usize, min_max_usize, 0usize, !0usize); - - bounds_test!(i8, min_max_i8, - -1i8 << (((::std::mem::size_of::() as i8)*8i8)-1i8), - !(-1i8 << (((::std::mem::size_of::() as i8)*8i8)-1i8))); - bounds_test!(i16, min_max_i16, - -1i16 << (((::std::mem::size_of::() as i16)*8i16)-1i16), - !(-1i16 << (((::std::mem::size_of::() as i16)*8i16)-1i16))); - bounds_test!(i32, min_max_i32, - -1i32 << (((::std::mem::size_of::() as i32)*8i32)-1i32), - !(-1i32 << (((::std::mem::size_of::() as i32)*8i32)-1i32))); - bounds_test!(i64, min_max_i64, - -1i64 << (((::std::mem::size_of::() as i64)*8i64)-1i64), - !(-1i64 << (((::std::mem::size_of::() as i64)*8i64)-1i64))); - bounds_test!(isize, min_max_isize, - -1isize << (((::std::mem::size_of::() as isize)*8isize)-1isize), - !(-1isize << (((::std::mem::size_of::() as isize)*8isize)-1isize))); - - bounds_test!(f32, min_max_f32, - -3.40282347e+38f32, 3.40282347e+38f32); - bounds_test!(f64, min_max_f64, - -1.7976931348623157e+308f64, - 1.7976931348623157e+308f64); -} diff --git a/src/lib.rs b/src/lib.rs index 4d697cc..dfbc655 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,13 +2,12 @@ //! License: Proprietary //! //! -//#![feature(float_extras)] -//#![feature(associated_consts)] #![no_std] extern crate core as std; extern crate binding; extern crate pact; +extern crate weave; @@ -17,7 +16,6 @@ mod macros; mod zero; mod one; -mod bounded; mod number; mod whole; mod integer; @@ -39,5 +37,4 @@ pub use self::whole::Whole; pub use self::integer::Integer; pub use self::real::Real; pub use self::constants::Constants; -pub use self::bounded::Bounded; pub use self::trig::{Degree, Radian, Trig}; diff --git a/src/matrix.rs b/src/matrix.rs index c687dd0..3b74bb9 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -11,7 +11,9 @@ use ::vector::{Vector, Vector2, Vector3, Vector4}; /// functions a [Matrix][1] must implement. /// /// [1]: https://en.wikipedia.org/ -pub trait Matrix : Sized where T: Number, VT: Vector +pub trait Matrix : Sized + where T: Number, + VT: Vector { /// Create a Matrix with the given value set /// for all the diagonal values. diff --git a/src/number.rs b/src/number.rs index 7d71f11..962e9a7 100644 --- a/src/number.rs +++ b/src/number.rs @@ -5,9 +5,10 @@ use std::ops::{Add, Sub, Mul, Div, Rem}; use std::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign}; use std::str::FromStr; +use weave::Bounded; + use ::zero::Zero; use ::one::One; -use ::bounded::Bounded; /// A trait that defines what is required to be considered