2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2021-05-21 12:35:49 -05:00
|
|
|
#![allow(dead_code)]
|
2015-01-07 19:25:56 -06:00
|
|
|
|
2012-12-06 20:32:13 -06:00
|
|
|
trait T {
|
|
|
|
fn print(&self);
|
|
|
|
}
|
|
|
|
|
2015-01-28 07:34:18 -06:00
|
|
|
#[derive(Debug)]
|
2012-12-06 20:32:13 -06:00
|
|
|
struct S {
|
2015-03-25 19:06:52 -05:00
|
|
|
s: isize,
|
2012-12-06 20:32:13 -06:00
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl T for S {
|
2012-12-06 20:32:13 -06:00
|
|
|
fn print(&self) {
|
2014-12-20 02:09:35 -06:00
|
|
|
println!("{:?}", self);
|
2012-12-06 20:32:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:47:21 -05:00
|
|
|
fn print_t(t: &dyn T) {
|
2012-12-06 20:32:13 -06:00
|
|
|
t.print();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn print_s(s: &S) {
|
|
|
|
s.print();
|
|
|
|
}
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2022-07-06 21:36:10 -05:00
|
|
|
let s: Box<S> = Box::new(S { s: 5 });
|
2014-07-07 18:35:15 -05:00
|
|
|
print_s(&*s);
|
2019-05-28 13:47:21 -05:00
|
|
|
let t: Box<dyn T> = s as Box<dyn T>;
|
2014-08-28 22:21:28 -05:00
|
|
|
print_t(&*t);
|
2012-12-06 20:32:13 -06:00
|
|
|
}
|