mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 10:45:18 +00:00
26 lines
443 B
Rust
26 lines
443 B
Rust
// run-pass
|
|
#![allow(dead_code)]
|
|
trait Trait<T> {
|
|
fn f(&self, x: T);
|
|
}
|
|
|
|
#[derive(Copy, Clone)]
|
|
struct Struct {
|
|
x: isize,
|
|
y: isize,
|
|
}
|
|
|
|
impl Trait<&'static str> for Struct {
|
|
fn f(&self, x: &'static str) {
|
|
println!("Hi, {}!", x);
|
|
}
|
|
}
|
|
|
|
pub fn main() {
|
|
let a = Struct { x: 1, y: 2 };
|
|
let b: Box<dyn Trait<&'static str>> = Box::new(a);
|
|
b.f("Mary");
|
|
let c: &dyn Trait<&'static str> = &a;
|
|
c.f("Joe");
|
|
}
|