2018-08-30 14:18:55 +02:00
|
|
|
//@ run-pass
|
2012-10-05 16:55:42 -07:00
|
|
|
trait Foo {
|
2015-03-25 17:06:52 -07:00
|
|
|
fn f(&self) -> isize;
|
2012-10-05 16:55:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
struct A {
|
2015-03-25 17:06:52 -07:00
|
|
|
x: isize
|
2012-10-05 16:55:42 -07:00
|
|
|
}
|
|
|
|
|
2013-02-14 11:47:00 -08:00
|
|
|
impl Foo for A {
|
2015-03-25 17:06:52 -07:00
|
|
|
fn f(&self) -> isize {
|
2014-01-09 21:06:55 +11:00
|
|
|
println!("Today's number is {}", self.x);
|
2012-10-05 16:55:42 -07:00
|
|
|
return self.x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2012-10-05 16:55:42 -07:00
|
|
|
let a = A { x: 3 };
|
2019-05-28 14:47:21 -04:00
|
|
|
let b = (&a) as &dyn Foo;
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(b.f(), 3);
|
2012-10-05 16:55:42 -07:00
|
|
|
}
|