2012-12-12 18:50:28 -06:00
|
|
|
pub trait Number: NumConv {
|
2013-01-30 21:42:06 -06:00
|
|
|
static pure fn from<T:Number>(n: T) -> Self;
|
2012-12-12 18:50:28 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub impl float: Number {
|
|
|
|
static pure fn from<T:Number>(n: T) -> float { n.to_float() }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait NumConv {
|
|
|
|
pure fn to_float(&self) -> float;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub impl float: NumConv {
|
|
|
|
pure fn to_float(&self) -> float { *self }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let _: float = Number::from(0.0f);
|
2013-01-30 21:42:06 -06:00
|
|
|
}
|