| Matthias Benkard | f3a3b30 | 2019-02-28 12:13:56 +0100 | [diff] [blame] | 1 | pub struct Person { |
| 2 | pub age: i32, | ||||
| 3 | pub name: String, | ||||
| 4 | } | ||||
| 5 | |||||
| 6 | impl ToString for Person { | ||||
| 7 | /// # Examples | ||||
| 8 | /// | ||||
| 9 | /// ``` | ||||
| 10 | /// use rust_tutorial::Person; | ||||
| 11 | /// | ||||
| 12 | /// let p = Person { age: 30, name: "Mary".to_string() }; | ||||
| 13 | /// assert_eq!(p.to_string(), "Mary (30)"); | ||||
| 14 | /// ``` | ||||
| 15 | fn to_string(&self) -> String { | ||||
| 16 | format!("{} ({})", self.name, self.age) | ||||
| 17 | } | ||||
| 18 | } | ||||
| 19 | |||||
| 20 | #[test] | ||||
| 21 | fn test_example() { | ||||
| 22 | assert_eq!("a", "a"); | ||||
| 23 | } | ||||