Rename cast module to conv and NumCast trait to NumConv

These names will be more appropriate once the cast function has been completely phased out.
This commit is contained in:
Brendan Zabarauskas 2012-12-05 10:33:27 +10:00
parent e2857c6e7e
commit b8521f289c
6 changed files with 50 additions and 50 deletions

View file

@ -4,7 +4,7 @@ use core::f64::consts::pi;
use funs::triganomic::{cos, sin}; use funs::triganomic::{cos, sin};
use mat::{Mat3, Mat4}; use mat::{Mat3, Mat4};
use num::kinds::{Float, Number}; use num::kinds::{Float, Number};
use num::cast::{NumCast, cast}; use num::conv::cast;
use quat::Quat; use quat::Quat;
use vec::Vec3; use vec::Vec3;

View file

@ -5,7 +5,7 @@
* (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf). * (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf).
*/ */
use angle::Radians; use angle::Radians;
use num::cast::cast; use num::conv::cast;
use num::kinds::Number; use num::kinds::Number;
use vec::{Vec3, Vec2, Vec4}; use vec::{Vec3, Vec2, Vec4};

View file

@ -64,8 +64,8 @@ pub mod funs {
} }
pub mod num { pub mod num {
#[path = "num/cast.rs"] #[path = "num/conv.rs"]
pub mod cast; pub mod conv;
#[path = "num/default_eq.rs"] #[path = "num/default_eq.rs"]
pub mod default_eq; pub mod default_eq;
#[path = "num/kinds.rs"] #[path = "num/kinds.rs"]

View file

@ -9,7 +9,7 @@ use std::cmp::FuzzyEq;
use dim::{Dimensional, ToPtr}; use dim::{Dimensional, ToPtr};
use funs::common::*; use funs::common::*;
use funs::exponential::*; use funs::exponential::*;
use num::cast::*; use num::conv::cast;
use num::kinds::{Float, Number}; use num::kinds::{Float, Number};
use quat::{Quat, ToQuat}; use quat::{Quat, ToQuat};
use vec::{NumericVector, Vec2, Vec3, Vec4}; use vec::{NumericVector, Vec2, Vec3, Vec4};

View file

@ -6,11 +6,11 @@
* static constructor method. I feel that this will be far clearer than using * static constructor method. I feel that this will be far clearer than using
* the `cast` function everywhere. * the `cast` function everywhere.
*/ */
pub trait NumCast { pub trait NumConv {
// TODO: the plan is to remove the `from` and `cast` methods and use the // TODO: the plan is to remove the `from` and `cast` methods and use the
// `num::kinds::Number::from<T:Number(n: T)` method instead // `num::kinds::Number::from<T:Number(n: T)` method instead
static pure fn from<T:NumCast>(n: T) -> self; static pure fn from<T:NumConv>(n: T) -> self;
pure fn cast<T:NumCast>(&self) -> T; pure fn cast<T:NumConv>(&self) -> T;
pure fn to_u8(&self) -> u8; pure fn to_u8(&self) -> u8;
pure fn to_u16(&self) -> u16; pure fn to_u16(&self) -> u16;
@ -30,11 +30,11 @@ pub trait NumCast {
} }
#[inline(always)] #[inline(always)]
pub pure fn cast<T:NumCast, U:NumCast>(n: T) -> U { n.cast() } pub pure fn cast<T:NumConv, U:NumConv>(n: T) -> U { n.cast() }
pub impl u8: NumCast { pub impl u8: NumConv {
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> u8 { n.to_u8() } #[inline(always)] static pure fn from<T:NumConv>(n: T) -> u8 { n.to_u8() }
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) } #[inline(always)] pure fn cast<T:NumConv>(&self) -> T { NumConv::from(*self) }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self } #[inline(always)] pure fn to_u8(&self) -> u8 { *self }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[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 } #[inline(always)] pure fn to_float(&self) -> float { *self as float }
} }
pub impl u16: NumCast { pub impl u16: NumConv {
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> u16 { n.to_u16() } #[inline(always)] static pure fn from<T:NumConv>(n: T) -> u16 { n.to_u16() }
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) } #[inline(always)] pure fn cast<T:NumConv>(&self) -> T { NumConv::from(*self) }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self } #[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 } #[inline(always)] pure fn to_float(&self) -> float { *self as float }
} }
pub impl u32: NumCast { pub impl u32: NumConv {
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> u32 { n.to_u32() } #[inline(always)] static pure fn from<T:NumConv>(n: T) -> u32 { n.to_u32() }
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) } #[inline(always)] pure fn cast<T:NumConv>(&self) -> T { NumConv::from(*self) }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[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 } #[inline(always)] pure fn to_float(&self) -> float { *self as float }
} }
pub impl u64: NumCast { pub impl u64: NumConv {
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> u64 { n.to_u64() } #[inline(always)] static pure fn from<T:NumConv>(n: T) -> u64 { n.to_u64() }
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) } #[inline(always)] pure fn cast<T:NumConv>(&self) -> T { NumConv::from(*self) }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[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 } #[inline(always)] pure fn to_float(&self) -> float { *self as float }
} }
pub impl uint: NumCast { pub impl uint: NumConv {
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> uint { n.to_uint() } #[inline(always)] static pure fn from<T:NumConv>(n: T) -> uint { n.to_uint() }
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) } #[inline(always)] pure fn cast<T:NumConv>(&self) -> T { NumConv::from(*self) }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[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 } #[inline(always)] pure fn to_float(&self) -> float { *self as float }
} }
pub impl i8: NumCast { pub impl i8: NumConv {
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> i8 { n.to_i8() } #[inline(always)] static pure fn from<T:NumConv>(n: T) -> i8 { n.to_i8() }
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) } #[inline(always)] pure fn cast<T:NumConv>(&self) -> T { NumConv::from(*self) }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[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 } #[inline(always)] pure fn to_float(&self) -> float { *self as float }
} }
pub impl i16: NumCast { pub impl i16: NumConv {
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> i16 { n.to_i16() } #[inline(always)] static pure fn from<T:NumConv>(n: T) -> i16 { n.to_i16() }
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) } #[inline(always)] pure fn cast<T:NumConv>(&self) -> T { NumConv::from(*self) }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[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 } #[inline(always)] pure fn to_float(&self) -> float { *self as float }
} }
pub impl i32: NumCast { pub impl i32: NumConv {
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> i32 { n.to_i32() } #[inline(always)] static pure fn from<T:NumConv>(n: T) -> i32 { n.to_i32() }
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) } #[inline(always)] pure fn cast<T:NumConv>(&self) -> T { NumConv::from(*self) }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[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 } #[inline(always)] pure fn to_float(&self) -> float { *self as float }
} }
pub impl i64: NumCast { pub impl i64: NumConv {
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> i64 { n.to_i64() } #[inline(always)] static pure fn from<T:NumConv>(n: T) -> i64 { n.to_i64() }
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) } #[inline(always)] pure fn cast<T:NumConv>(&self) -> T { NumConv::from(*self) }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[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 } #[inline(always)] pure fn to_float(&self) -> float { *self as float }
} }
pub impl int: NumCast { pub impl int: NumConv {
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> int { n.to_int() } #[inline(always)] static pure fn from<T:NumConv>(n: T) -> int { n.to_int() }
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) } #[inline(always)] pure fn cast<T:NumConv>(&self) -> T { NumConv::from(*self) }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[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 } #[inline(always)] pure fn to_float(&self) -> float { *self as float }
} }
pub impl f32: NumCast { pub impl f32: NumConv {
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> f32 { n.to_f32() } #[inline(always)] static pure fn from<T:NumConv>(n: T) -> f32 { n.to_f32() }
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) } #[inline(always)] pure fn cast<T:NumConv>(&self) -> T { NumConv::from(*self) }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[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 } #[inline(always)] pure fn to_float(&self) -> float { *self as float }
} }
pub impl f64: NumCast { pub impl f64: NumConv {
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> f64 { n.to_f64() } #[inline(always)] static pure fn from<T:NumConv>(n: T) -> f64 { n.to_f64() }
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) } #[inline(always)] pure fn cast<T:NumConv>(&self) -> T { NumConv::from(*self) }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[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 } #[inline(always)] pure fn to_float(&self) -> float { *self as float }
} }
pub impl float: NumCast { pub impl float: NumConv {
#[inline(always)] static pure fn from<T:NumCast>(n: T) -> float { n.to_float() } #[inline(always)] static pure fn from<T:NumConv>(n: T) -> float { n.to_float() }
#[inline(always)] pure fn cast<T:NumCast>(&self) -> T { NumCast::from(*self) } #[inline(always)] pure fn cast<T:NumConv>(&self) -> T { NumConv::from(*self) }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 } #[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 } #[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }

View file

@ -1,11 +1,11 @@
use core::cmp::{Eq, Ord}; use core::cmp::{Eq, Ord};
use std::cmp::FuzzyEq; use std::cmp::FuzzyEq;
use num::cast::NumCast; use num::conv::NumConv;
use num::default_eq::DefaultEq; 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` * Construct a number from the type `T:Number`
*/ */