diff --git a/src/angle.rs b/src/angle.rs index 4f6e93f..65a9275 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -4,7 +4,7 @@ use core::f64::consts::pi; use funs::triganomic::{cos, sin}; use mat::{Mat3, Mat4}; use num::kinds::{Float, Number}; -use num::cast::{NumCast, cast}; +use num::conv::cast; use quat::Quat; use vec::Vec3; diff --git a/src/funs/triganomic.rs b/src/funs/triganomic.rs index 77502d5..c56ddae 100644 --- a/src/funs/triganomic.rs +++ b/src/funs/triganomic.rs @@ -5,7 +5,7 @@ * (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf). */ use angle::Radians; -use num::cast::cast; +use num::conv::cast; use num::kinds::Number; use vec::{Vec3, Vec2, Vec4}; diff --git a/src/lmath.rc b/src/lmath.rc index a1648ad..a9d2b38 100644 --- a/src/lmath.rc +++ b/src/lmath.rc @@ -64,8 +64,8 @@ pub mod funs { } pub mod num { - #[path = "num/cast.rs"] - pub mod cast; + #[path = "num/conv.rs"] + pub mod conv; #[path = "num/default_eq.rs"] pub mod default_eq; #[path = "num/kinds.rs"] diff --git a/src/mat.rs b/src/mat.rs index dcd09a7..f98248b 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -9,7 +9,7 @@ use std::cmp::FuzzyEq; use dim::{Dimensional, ToPtr}; use funs::common::*; use funs::exponential::*; -use num::cast::*; +use num::conv::cast; use num::kinds::{Float, Number}; use quat::{Quat, ToQuat}; use vec::{NumericVector, Vec2, Vec3, Vec4}; diff --git a/src/num/cast.rs b/src/num/conv.rs similarity index 85% rename from src/num/cast.rs rename to src/num/conv.rs index 01e4efa..6bad97a 100644 --- a/src/num/cast.rs +++ b/src/num/conv.rs @@ -6,11 +6,11 @@ * static constructor method. I feel that this will be far clearer than using * the `cast` function everywhere. */ -pub trait NumCast { +pub trait NumConv { // TODO: the plan is to remove the `from` and `cast` methods and use the // `num::kinds::Number::from(n: T) -> self; - pure fn cast(&self) -> T; + static pure fn from(n: T) -> self; + pure fn cast(&self) -> T; pure fn to_u8(&self) -> u8; pure fn to_u16(&self) -> u16; @@ -30,11 +30,11 @@ pub trait NumCast { } #[inline(always)] -pub pure fn cast(n: T) -> U { n.cast() } +pub pure fn cast(n: T) -> U { n.cast() } -pub impl u8: NumCast { - #[inline(always)] static pure fn from(n: T) -> u8 { n.to_u8() } - #[inline(always)] pure fn cast(&self) -> T { NumCast::from(*self) } +pub impl u8: NumConv { + #[inline(always)] static pure fn from(n: T) -> u8 { n.to_u8() } + #[inline(always)] pure fn cast(&self) -> T { NumConv::from(*self) } #[inline(always)] pure fn to_u8(&self) -> u8 { *self } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } @@ -53,9 +53,9 @@ pub impl u8: NumCast { #[inline(always)] pure fn to_float(&self) -> float { *self as float } } -pub impl u16: NumCast { - #[inline(always)] static pure fn from(n: T) -> u16 { n.to_u16() } - #[inline(always)] pure fn cast(&self) -> T { NumCast::from(*self) } +pub impl u16: NumConv { + #[inline(always)] static pure fn from(n: T) -> u16 { n.to_u16() } + #[inline(always)] pure fn cast(&self) -> T { NumConv::from(*self) } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self } @@ -74,9 +74,9 @@ pub impl u16: NumCast { #[inline(always)] pure fn to_float(&self) -> float { *self as float } } -pub impl u32: NumCast { - #[inline(always)] static pure fn from(n: T) -> u32 { n.to_u32() } - #[inline(always)] pure fn cast(&self) -> T { NumCast::from(*self) } +pub impl u32: NumConv { + #[inline(always)] static pure fn from(n: T) -> u32 { n.to_u32() } + #[inline(always)] pure fn cast(&self) -> T { NumConv::from(*self) } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } @@ -95,9 +95,9 @@ pub impl u32: NumCast { #[inline(always)] pure fn to_float(&self) -> float { *self as float } } -pub impl u64: NumCast { - #[inline(always)] static pure fn from(n: T) -> u64 { n.to_u64() } - #[inline(always)] pure fn cast(&self) -> T { NumCast::from(*self) } +pub impl u64: NumConv { + #[inline(always)] static pure fn from(n: T) -> u64 { n.to_u64() } + #[inline(always)] pure fn cast(&self) -> T { NumConv::from(*self) } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } @@ -116,9 +116,9 @@ pub impl u64: NumCast { #[inline(always)] pure fn to_float(&self) -> float { *self as float } } -pub impl uint: NumCast { - #[inline(always)] static pure fn from(n: T) -> uint { n.to_uint() } - #[inline(always)] pure fn cast(&self) -> T { NumCast::from(*self) } +pub impl uint: NumConv { + #[inline(always)] static pure fn from(n: T) -> uint { n.to_uint() } + #[inline(always)] pure fn cast(&self) -> T { NumConv::from(*self) } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } @@ -137,9 +137,9 @@ pub impl uint: NumCast { #[inline(always)] pure fn to_float(&self) -> float { *self as float } } -pub impl i8: NumCast { - #[inline(always)] static pure fn from(n: T) -> i8 { n.to_i8() } - #[inline(always)] pure fn cast(&self) -> T { NumCast::from(*self) } +pub impl i8: NumConv { + #[inline(always)] static pure fn from(n: T) -> i8 { n.to_i8() } + #[inline(always)] pure fn cast(&self) -> T { NumConv::from(*self) } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } @@ -158,9 +158,9 @@ pub impl i8: NumCast { #[inline(always)] pure fn to_float(&self) -> float { *self as float } } -pub impl i16: NumCast { - #[inline(always)] static pure fn from(n: T) -> i16 { n.to_i16() } - #[inline(always)] pure fn cast(&self) -> T { NumCast::from(*self) } +pub impl i16: NumConv { + #[inline(always)] static pure fn from(n: T) -> i16 { n.to_i16() } + #[inline(always)] pure fn cast(&self) -> T { NumConv::from(*self) } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } @@ -179,9 +179,9 @@ pub impl i16: NumCast { #[inline(always)] pure fn to_float(&self) -> float { *self as float } } -pub impl i32: NumCast { - #[inline(always)] static pure fn from(n: T) -> i32 { n.to_i32() } - #[inline(always)] pure fn cast(&self) -> T { NumCast::from(*self) } +pub impl i32: NumConv { + #[inline(always)] static pure fn from(n: T) -> i32 { n.to_i32() } + #[inline(always)] pure fn cast(&self) -> T { NumConv::from(*self) } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } @@ -200,9 +200,9 @@ pub impl i32: NumCast { #[inline(always)] pure fn to_float(&self) -> float { *self as float } } -pub impl i64: NumCast { - #[inline(always)] static pure fn from(n: T) -> i64 { n.to_i64() } - #[inline(always)] pure fn cast(&self) -> T { NumCast::from(*self) } +pub impl i64: NumConv { + #[inline(always)] static pure fn from(n: T) -> i64 { n.to_i64() } + #[inline(always)] pure fn cast(&self) -> T { NumConv::from(*self) } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } @@ -221,9 +221,9 @@ pub impl i64: NumCast { #[inline(always)] pure fn to_float(&self) -> float { *self as float } } -pub impl int: NumCast { - #[inline(always)] static pure fn from(n: T) -> int { n.to_int() } - #[inline(always)] pure fn cast(&self) -> T { NumCast::from(*self) } +pub impl int: NumConv { + #[inline(always)] static pure fn from(n: T) -> int { n.to_int() } + #[inline(always)] pure fn cast(&self) -> T { NumConv::from(*self) } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } @@ -242,9 +242,9 @@ pub impl int: NumCast { #[inline(always)] pure fn to_float(&self) -> float { *self as float } } -pub impl f32: NumCast { - #[inline(always)] static pure fn from(n: T) -> f32 { n.to_f32() } - #[inline(always)] pure fn cast(&self) -> T { NumCast::from(*self) } +pub impl f32: NumConv { + #[inline(always)] static pure fn from(n: T) -> f32 { n.to_f32() } + #[inline(always)] pure fn cast(&self) -> T { NumConv::from(*self) } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } @@ -263,9 +263,9 @@ pub impl f32: NumCast { #[inline(always)] pure fn to_float(&self) -> float { *self as float } } -pub impl f64: NumCast { - #[inline(always)] static pure fn from(n: T) -> f64 { n.to_f64() } - #[inline(always)] pure fn cast(&self) -> T { NumCast::from(*self) } +pub impl f64: NumConv { + #[inline(always)] static pure fn from(n: T) -> f64 { n.to_f64() } + #[inline(always)] pure fn cast(&self) -> T { NumConv::from(*self) } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } @@ -284,9 +284,9 @@ pub impl f64: NumCast { #[inline(always)] pure fn to_float(&self) -> float { *self as float } } -pub impl float: NumCast { - #[inline(always)] static pure fn from(n: T) -> float { n.to_float() } - #[inline(always)] pure fn cast(&self) -> T { NumCast::from(*self) } +pub impl float: NumConv { + #[inline(always)] static pure fn from(n: T) -> float { n.to_float() } + #[inline(always)] pure fn cast(&self) -> T { NumConv::from(*self) } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } diff --git a/src/num/kinds.rs b/src/num/kinds.rs index 5f8a466..8ca027a 100644 --- a/src/num/kinds.rs +++ b/src/num/kinds.rs @@ -1,11 +1,11 @@ use core::cmp::{Eq, Ord}; use std::cmp::FuzzyEq; -use num::cast::NumCast; +use num::conv::NumConv; use num::default_eq::DefaultEq; -pub trait Number: DefaultEq, Eq, Num, NumCast, Ord { +pub trait Number: DefaultEq, Eq, Num, NumConv, Ord { /** * Construct a number from the type `T:Number` */