blob: aa513277830128d70f11828117d92aa69fba4ea3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
// run-pass
#![feature(box_syntax)]
struct Dog {
name : String
}
trait Barks {
fn bark(&self) -> String;
}
impl Barks for Dog {
fn bark(&self) -> String {
return format!("woof! (I'm {})", self.name);
}
}
pub fn main() {
let snoopy = box Dog{name: "snoopy".to_string()};
let bubbles = box Dog{name: "bubbles".to_string()};
let barker = [snoopy as Box<dyn Barks>, bubbles as Box<dyn Barks>];
for pup in &barker {
println!("{}", pup.bark());
}
}
|