2018-08-30 14:18:55 +02:00
|
|
|
//@ run-pass
|
2018-09-25 23:51:35 +02:00
|
|
|
#![allow(dead_code)]
|
2013-12-27 00:38:28 -05:00
|
|
|
trait Trait<T> {
|
|
|
|
fn f(&self, x: T);
|
|
|
|
}
|
|
|
|
|
2015-03-30 09:38:27 -04:00
|
|
|
#[derive(Copy, Clone)]
|
2013-12-27 00:38:28 -05:00
|
|
|
struct Struct {
|
2015-03-25 17:06:52 -07:00
|
|
|
x: isize,
|
|
|
|
y: isize,
|
2013-12-27 00:38:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Trait<&'static str> for Struct {
|
|
|
|
fn f(&self, x: &'static str) {
|
2014-01-09 21:06:55 +11:00
|
|
|
println!("Hi, {}!", x);
|
2013-12-27 00:38:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
let a = Struct { x: 1, y: 2 };
|
2019-05-28 14:47:21 -04:00
|
|
|
let b: Box<dyn Trait<&'static str>> = Box::new(a);
|
2014-02-07 00:38:33 +02:00
|
|
|
b.f("Mary");
|
2019-05-28 14:47:21 -04:00
|
|
|
let c: &dyn Trait<&'static str> = &a;
|
2014-02-07 00:38:33 +02:00
|
|
|
c.f("Joe");
|
2013-12-27 00:38:28 -05:00
|
|
|
}
|