blob: 95038433e8cddf4b386749efbb3d511d43e99ff7 [file] [log] [blame]
pub trait Summary {
fn summarize(&self) -> String;
}
pub struct NewsArticle {
pub headline: String,
pub location: String,
pub author: String,
pub content: String,
}
impl Summary for NewsArticle {
fn summarize(&self) -> String {
format!("{}, by {} ({})", self.headline, self.author, self.location)
}
}
pub struct Tweet {
pub username: String,
pub content: String,
pub reply: bool,
pub retweet: bool,
}
impl Summary for Tweet {
fn summarize(&self) -> String {
format!("{}: {}", self.username, self.content)
}
}
// ANCHOR: here
pub fn notify(item: impl Summary) {
println!("Breaking news! {}", item.summarize());
}
// ANCHOR_END: here