2019-07-26 21:54:25 +00:00
|
|
|
// run-pass
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn f(x: Box<isize>) {
|
|
|
|
let y: &isize = &*x;
|
2014-05-02 21:53:33 +00: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 18:47:21 +00:00
|
|
|
fn g(x: Box<dyn Trait>) {
|
2014-05-02 21:53:33 +00:00
|
|
|
x.printme();
|
2019-05-28 18:47:21 +00:00
|
|
|
let y: &dyn Trait = &*x;
|
2014-05-02 21:53:33 +00:00
|
|
|
y.printme();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2021-08-25 00:39:40 +00:00
|
|
|
f(Box::new(1234));
|
|
|
|
g(Box::new(Struct) as Box<dyn Trait>);
|
2014-05-02 21:53:33 +00:00
|
|
|
}
|