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