Skip to content

Commit 5e02b9f

Browse files
Traits as parameters
1 parent f120e8d commit 5e02b9f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

rustlang_book/traits/src/main.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ impl Summary for Tweet {
2525
return format!("{}: {}", self.username, self.content);
2626
}
2727
}
28+
29+
pub fn notify(item: &impl Summary) {
30+
println!("Breaking news!! {}", item.summarize());
31+
}
32+
2833
fn main() {
2934
let tweet = Tweet {
3035
username: String::from("just_a_kid_with_a_dream"),
@@ -33,7 +38,7 @@ fn main() {
3338
retweet: false,
3439
};
3540

36-
println!("1 new tweet: {}", tweet.summarize());
41+
notify(&tweet);
3742

3843
let article = NewsArticle {
3944
headline: String::from("Penguins win the Stanley Cup Championship!"),
@@ -45,5 +50,5 @@ fn main() {
4550
),
4651
};
4752

48-
println!("New article available! {}", article.summarize());
53+
notify(&article);
4954
}

0 commit comments

Comments
 (0)