1 2 3 4 5 6 7 8 9 10 11 12 13 14
pub struct Player { pub name: String, pub score: i32, } impl Player { pub fn new(name: String, score: i32) -> Player { Player { name, score } } pub fn describe(&self) -> String { format!("{} has scored: {}", self.name, self.score) } }