Implement a Trait for One Type
10 points
Implement Greet for Robot, so greet returns the robot's name, upper-cased, wrapped in a fixed announcement of format `BEEP BOOP, I AM <name>`. This is the smallest possible trait: one method, one implementor, no default body.
Required signature
pub trait Greet { fn greet(&self) -> String; } pub struct Robot { pub name: String, } impl Greet for Robot { fn greet(&self) -> String; }
Visible tests
-
greets_by_name#[test] fn greets_by_name() { let r = Robot { name: "R2D2".to_string() }; assert_eq!(r.greet(), "BEEP BOOP, I AM R2D2"); }
Your solution
Log in to submit a solution.