Add NumCast trait for generic numeric type casts
This commit is contained in:
parent
0f04df8522
commit
48b2141b83
24 changed files with 1041 additions and 88 deletions
|
@ -9,13 +9,13 @@
|
|||
// except according to those terms.
|
||||
|
||||
use cmp::{Eq, Ord};
|
||||
use num::Num::from_int;
|
||||
use num::NumCast::from;
|
||||
|
||||
pub trait NumExt: Eq Ord Num {}
|
||||
pub trait NumExt: Eq Ord Num NumCast {}
|
||||
|
||||
pub impl f32: NumExt {}
|
||||
|
||||
fn num_eq_one<T:NumExt>(n: T) { io::println(fmt!("%?", n == from_int(1))) }
|
||||
fn num_eq_one<T:NumExt>(n: T) { io::println(fmt!("%?", n == from(1))) }
|
||||
|
||||
pub fn main() {
|
||||
num_eq_one(1f32); // you need to actually use the function to trigger the ICE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue