Traits #2
https://doc.rust-lang.org/book/traits.html
既存の型を拡張できる。Rubyっぽい。
impl HasArea for i32 { fn area(&self) -> f64 { println!("this is silly"); *self as f64 } } fn main() { 5.area(); }
https://doc.rust-lang.org/book/traits.html
既存の型を拡張できる。Rubyっぽい。
impl HasArea for i32 { fn area(&self) -> f64 { println!("this is silly"); *self as f64 } } fn main() { 5.area(); }