A Default Method You Can Override
10 points
Summary::summarize has a default body. Implement it for Tweet so it overrides the default with "@username: content". Draft's impl is already given, empty — it deliberately falls through to the default, which your Tweet impl must not touch.
Required signature
pub trait Summary { fn summarize(&self) -> String { String::from("(no summary available)") } } pub struct Tweet { pub username: String, pub content: String, } impl Summary for Tweet { fn summarize(&self) -> String; } pub struct Draft; impl Summary for Draft {}
Visible tests
-
overrides_for_tweet#[test] fn overrides_for_tweet() { let t = Tweet { username: "rustlang".to_string(), content: "1.80 is out".to_string() }; assert_eq!(t.summarize(), "@rustlang: 1.80 is out"); }
Your solution
Log in to submit a solution.