@@ -5,7 +5,7 @@ extern crate ordered_float;
55extern crate num_traits;
66
77pub use ordered_float:: * ;
8- pub use num_traits:: { Bounded , Float , FromPrimitive , One , Zero } ;
8+ pub use num_traits:: { Bounded , Float , FromPrimitive , One , ToPrimitive , Zero } ;
99pub use std:: cmp:: Ordering :: * ;
1010pub use std:: { f32, f64, panic} ;
1111
@@ -137,6 +137,24 @@ describe! not_nan32 {
137137 assert_eq!( NotNaN :: <f32 >:: from_f32( Float :: nan( ) ) , None ) ;
138138 assert_eq!( NotNaN :: <f32 >:: from_f64( Float :: nan( ) ) , None ) ;
139139 }
140+
141+ it "should implement ToPrimitive" {
142+ let x = NotNaN :: from( 42.0f32 ) ;
143+ assert_eq!( x. to_u8( ) , Some ( 42u8 ) ) ;
144+ assert_eq!( x. to_i8( ) , Some ( 42i8 ) ) ;
145+ assert_eq!( x. to_u16( ) , Some ( 42u16 ) ) ;
146+ assert_eq!( x. to_i16( ) , Some ( 42i16 ) ) ;
147+ assert_eq!( x. to_u32( ) , Some ( 42u32 ) ) ;
148+ assert_eq!( x. to_i32( ) , Some ( 42i32 ) ) ;
149+ assert_eq!( x. to_u64( ) , Some ( 42u64 ) ) ;
150+ assert_eq!( x. to_i64( ) , Some ( 42i64 ) ) ;
151+ assert_eq!( x. to_usize( ) , Some ( 42usize ) ) ;
152+ assert_eq!( x. to_isize( ) , Some ( 42isize ) ) ;
153+ assert_eq!( x. to_f32( ) , Some ( 42f32 ) ) ;
154+ assert_eq!( x. to_f32( ) , Some ( 42f32 ) ) ;
155+ assert_eq!( x. to_f64( ) , Some ( 42f64 ) ) ;
156+ assert_eq!( x. to_f64( ) , Some ( 42f64 ) ) ;
157+ }
140158}
141159
142160describe ! not_nan64 {
@@ -233,6 +251,24 @@ describe! not_nan64 {
233251 assert_eq!( NotNaN :: <f64 >:: from_f32( Float :: nan( ) ) , None ) ;
234252 assert_eq!( NotNaN :: <f64 >:: from_f64( Float :: nan( ) ) , None ) ;
235253 }
254+
255+ it "should implement ToPrimitive" {
256+ let x = NotNaN :: from( 42.0f64 ) ;
257+ assert_eq!( x. to_u8( ) , Some ( 42u8 ) ) ;
258+ assert_eq!( x. to_i8( ) , Some ( 42i8 ) ) ;
259+ assert_eq!( x. to_u16( ) , Some ( 42u16 ) ) ;
260+ assert_eq!( x. to_i16( ) , Some ( 42i16 ) ) ;
261+ assert_eq!( x. to_u32( ) , Some ( 42u32 ) ) ;
262+ assert_eq!( x. to_i32( ) , Some ( 42i32 ) ) ;
263+ assert_eq!( x. to_u64( ) , Some ( 42u64 ) ) ;
264+ assert_eq!( x. to_i64( ) , Some ( 42i64 ) ) ;
265+ assert_eq!( x. to_usize( ) , Some ( 42usize ) ) ;
266+ assert_eq!( x. to_isize( ) , Some ( 42isize ) ) ;
267+ assert_eq!( x. to_f32( ) , Some ( 42f32 ) ) ;
268+ assert_eq!( x. to_f32( ) , Some ( 42f32 ) ) ;
269+ assert_eq!( x. to_f64( ) , Some ( 42f64 ) ) ;
270+ assert_eq!( x. to_f64( ) , Some ( 42f64 ) ) ;
271+ }
236272}
237273
238274describe ! hashing {
0 commit comments