Merge pull request #78 from kennytm/master

impl PrimInt for primitive types, and remove some unstable features.
This commit is contained in:
Alex Crichton 2015-04-04 23:46:03 -07:00
commit 7861e4c6da
3 changed files with 11 additions and 17 deletions

View File

@ -38,14 +38,13 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE. // OF THE POSSIBILITY OF SUCH DAMAGE.
#![feature(core)]
#![feature(test)] #![feature(test)]
extern crate num; extern crate num;
extern crate test; extern crate test;
use std::str::FromStr; use std::str::FromStr;
use std::num::{FromPrimitive, ToPrimitive}; use num::traits::{FromPrimitive, ToPrimitive};
use test::Bencher; use test::Bencher;
@ -133,7 +132,7 @@ fn main() {
let n = if args.len() < 2 { let n = if args.len() < 2 {
DEFAULT_DIGITS DEFAULT_DIGITS
} else { } else {
FromStr::from_str(args[1].as_slice()).unwrap() FromStr::from_str(&args[1]).unwrap()
}; };
pidigits(n); pidigits(n);
} }

View File

@ -18,7 +18,6 @@
//! approximate a square root to arbitrary precision: //! approximate a square root to arbitrary precision:
//! //!
//! ``` //! ```
//! # #![feature(core)]
//! extern crate num; //! extern crate num;
//! //!
//! use num::FromPrimitive; //! use num::FromPrimitive;
@ -44,7 +43,7 @@
//! //!
//! [newt]: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method //! [newt]: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
//#![cfg_attr(test, deny(warnings))] //#![cfg_attr(test, deny(warnings))]
#![cfg_attr(test, feature(hash, test))] #![cfg_attr(test, feature(test))]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/num/", html_root_url = "http://doc.rust-lang.org/num/",
@ -145,5 +144,8 @@ pub fn pow<T: Clone + One + Mul<T, Output = T>>(mut base: T, mut exp: usize) ->
#[cfg(test)] #[cfg(test)]
fn hash<T: hash::Hash>(x: &T) -> u64 { fn hash<T: hash::Hash>(x: &T) -> u64 {
hash::hash::<T, hash::SipHasher>(x) use std::hash::Hasher;
let mut hasher = hash::SipHasher::new();
x.hash(&mut hasher);
hasher.finish()
} }

View File

@ -677,14 +677,6 @@ pub trait PrimInt
macro_rules! prim_int_impl { macro_rules! prim_int_impl {
($($T:ty)*) => ($( ($($T:ty)*) => ($(
impl PrimInt for $T { impl PrimInt for $T {
fn min_value() -> Self {
<$T>::min_value()
}
fn max_value() -> Self {
<$T>::max_value()
}
fn count_ones(self) -> u32 { fn count_ones(self) -> u32 {
<$T>::count_ones(self) <$T>::count_ones(self)
} }
@ -736,6 +728,8 @@ macro_rules! prim_int_impl {
)*) )*)
} }
prim_int_impl!(u8 u16 u32 u64 usize i8 i16 i32 i64 isize);
/// A generic trait for converting a value to a number. /// A generic trait for converting a value to a number.
pub trait ToPrimitive { pub trait ToPrimitive {
/// Converts the value of `self` to an `isize`. /// Converts the value of `self` to an `isize`.
@ -1329,8 +1323,8 @@ pub trait Float
/// predicate instead. /// predicate instead.
/// ///
/// ``` /// ```
/// # #![feature(core)] /// use num::traits::Float;
/// use std::num::{Float, FpCategory}; /// use std::num::FpCategory;
/// use std::f32; /// use std::f32;
/// ///
/// let num = 12.4f32; /// let num = 12.4f32;
@ -1880,7 +1874,6 @@ pub trait Float
/// the operations were performed separately. /// the operations were performed separately.
/// ///
/// ``` /// ```
/// # #![feature(std_misc, core)]
/// use num::traits::Float; /// use num::traits::Float;
/// use std::f64; /// use std::f64;
/// ///