diff --git a/src/lib.rs b/src/lib.rs index bc83066..7af9538 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,6 @@ //! //! #![feature(zero_one)] -#![feature(float_from_str_radix)] #![feature(float_extras)] #![feature(associated_consts)] diff --git a/src/number.rs b/src/number.rs index ce5129f..6f13328 100644 --- a/src/number.rs +++ b/src/number.rs @@ -2,6 +2,7 @@ use std::cmp::PartialEq; use std::mem::size_of; use std::num::{Zero, One}; use std::ops::{Add, Sub, Mul, Div, Rem}; +use std::str::FromStr; use super::bounded::Bounded; @@ -770,7 +771,13 @@ macro_rules! float_number_trait_impl fn from_str_radix(src: &str, radix: u32) -> Result { - <$varType>::from_str_radix(src, radix) + // TODO: Currently this will panic on a non base 10 radix. + // This is because the std library deprecated the + // from_str_radix function. Until a function can be + // written this will use the from_str function and + // panic for non base 10 requests. + assert!(radix == 10); + <$varType>::from_str(src) } } )*) diff --git a/src/vector.rs b/src/vector.rs index 943c2f6..a47c322 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -47,6 +47,12 @@ pub trait Vector : Clone where T: Number } + // Property functions. + /// Returns the size, how many components the Vector + /// has, of this Vector. + fn get_size(&self) -> u8; + + // Scalar operations that change this Vector. /// Add a scalar value to this Vector. /// @@ -511,7 +517,7 @@ macro_rules! binary_operator_impl /// that implements the Vector trait. macro_rules! define_vector { - ($structName: ident <$T: ident> {$($field: ident),+}) => + ($structName: ident <$T: ident> {$($field: ident),+}, $field_count: expr) => { // Do not add a where clause here or implementing // generic traits were the generic is different @@ -558,6 +564,11 @@ macro_rules! define_vector $structName {$($field: val),+} } + fn get_size(&self) -> u8 + { + $field_count + } + fn add_scalar(&mut self, scalar: T) { *self = &*self + scalar; @@ -665,9 +676,9 @@ macro_rules! define_vector // Define the Vector2, Vector3, and Vector4 structures. -define_vector!(Vector2 {x, y}); -define_vector!(Vector3 {x, y, z}); -define_vector!(Vector4 {x, y, z, w}); +define_vector!(Vector2 {x, y}, 2u8); +define_vector!(Vector3 {x, y, z}, 3u8); +define_vector!(Vector4 {x, y, z, w}, 4u8); // Implements operations specific to the different