learn_rust_demo/
lib.rs

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