/ Chapter10 / main.rs
main.rs
 1  pub trait Summary {
 2      fn summarize(&self) -> String;
 3  }
 4  
 5  pub struct NewsArticle {
 6      pub headline: String,
 7      pub location: String,
 8      pub author: String,
 9      pub content: String,
10  }
11  
12  impl Summary for NewsArticle {
13      fn summarize(&self) -> String {
14          format!("{}, by {} ({})", self.headline, self.author, self.location)
15      }
16  }
17  
18  pub struct Tweet {
19      pub username: String,
20      pub content: String,
21      pub reply: bool,
22      pub retweet: bool,
23  }
24  
25  impl Summary for Tweet {
26      fn summarize(&self) -> String {
27          format!("{}: {}", self.username, self.content)
28      }
29  }
30  fn main() {
31      println!("Hello, world!");
32  }