1pub trait Summary{
2 fn summarize(&self) -> String{
3 format!("Read more from {}...", self.summairze_author())
4 }
5 fn summairze_author(&self) -> String;
6
7}
8
9pub struct NewsArticle{
10 pub headline: String,
11 pub location: String,
12 pub author: String,
13 pub content: String,
14}
15
16impl Summary for NewsArticle{
17 fn summairze_author(&self) -> String {
18 format!("@{}", self.author)
19 }
20}
21
22pub struct Tweet{
23 pub username: String,
24 pub content: String,
25 pub reply: bool,
26 pub retweet: bool,
27}
28
29impl Summary for Tweet{
30 fn summarize(&self) -> String {
31 format!("{}: {}", self.username, self.content)
32 }
33 fn summairze_author(&self) -> String {
34 format!("@{}", self.username)
35 }
36}