2015-04-18 05:12:20 +00:00
|
|
|
pub trait ToPrimitive {
|
|
|
|
fn to_int(&self) -> isize { 0 }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToPrimitive for i32 {}
|
|
|
|
impl ToPrimitive for isize {}
|
2014-12-22 17:04:23 +00:00
|
|
|
|
2012-12-07 02:32:13 +00:00
|
|
|
trait Add {
|
2015-01-08 10:54:35 +00:00
|
|
|
fn to_int(&self) -> isize;
|
2019-05-28 18:46:13 +00:00
|
|
|
fn add_dynamic(&self, other: &dyn Add) -> isize;
|
2012-12-07 02:32:13 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 10:54:35 +00:00
|
|
|
impl Add for isize {
|
|
|
|
fn to_int(&self) -> isize { *self }
|
2019-05-28 18:46:13 +00:00
|
|
|
fn add_dynamic(&self, other: &dyn Add) -> isize {
|
2015-05-03 05:30:59 +00:00
|
|
|
self.to_int() + other.to_int() //~ ERROR multiple applicable items in scope
|
2012-12-07 02:32:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() { }
|