mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
22 lines
305 B
Rust
22 lines
305 B
Rust
//@ run-pass
|
|
trait Foo {
|
|
fn f(&self) -> isize;
|
|
}
|
|
|
|
struct A {
|
|
x: isize
|
|
}
|
|
|
|
impl Foo for A {
|
|
fn f(&self) -> isize {
|
|
println!("Today's number is {}", self.x);
|
|
return self.x;
|
|
}
|
|
}
|
|
|
|
pub fn main() {
|
|
let a = A { x: 3 };
|
|
let b = (&a) as &dyn Foo;
|
|
assert_eq!(b.f(), 3);
|
|
}
|