2019-07-26 16:54:25 -05:00
|
|
|
// run-pass
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
fn f(x: Box<isize>) {
|
|
|
|
let y: &isize = &*x;
|
2014-05-02 16:53:33 -05:00
|
|
|
println!("{}", *x);
|
|
|
|
println!("{}", *y);
|
|
|
|
}
|
|
|
|
|
|
|
|
trait Trait {
|
|
|
|
fn printme(&self);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Struct;
|
|
|
|
|
|
|
|
impl Trait for Struct {
|
|
|
|
fn printme(&self) {
|
|
|
|
println!("hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:47:21 -05:00
|
|
|
fn g(x: Box<dyn Trait>) {
|
2014-05-02 16:53:33 -05:00
|
|
|
x.printme();
|
2019-05-28 13:47:21 -05:00
|
|
|
let y: &dyn Trait = &*x;
|
2014-05-02 16:53:33 -05:00
|
|
|
y.printme();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2021-08-24 19:39:40 -05:00
|
|
|
f(Box::new(1234));
|
|
|
|
g(Box::new(Struct) as Box<dyn Trait>);
|
2014-05-02 16:53:33 -05:00
|
|
|
}
|