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