1pub trait Summary {
8 fn size(&self) -> String;
10
11 fn normal(&self) -> String {
13 String::from("(Read more...)")
14 }
15
16 fn summary_author(&self) -> String;
17
18 fn summary_fn(&self) -> String {
19 format!("(Read more form {} ...)", self.summary_author())
20 }
21}
22
23pub struct NewsArticle {
24 pub headline: String,
25 pub localhost: String,
26 pub author: String,
27 pub content:String,
28}
29
30impl Summary for NewsArticle {
31 fn size(&self) -> String {
32 format!("{}, by {} {}", self.headline, self.author, self.localhost)
33 }
34 fn summary_author(&self) -> String {
35 format!("{}", self.author)
36 }
37}
38
39pub struct Tweet {
40 pub username: String,
41 pub content: String,
42 pub reply:bool,
43 pub retweet:bool,
44}
45
46impl Summary for Tweet {
47 fn size(&self) -> String {
48 format!("{}:{}", self.username, self.content)
49 }
50
51 fn summary_author(&self) -> String {
52 format!("{}", self.username)
53 }
54}
55
56pub fn add_one(x: i32) -> i32 {
67 x + 1
68}