Last active
August 29, 2015 14:07
-
-
Save pzol/1ac9c4cf3ddd6bed46b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[deriving(Show, Clone, PartialEq)] | |
struct City<'a> { | |
name: &'a str, | |
country: &'a str | |
} | |
impl<'a> City<'a> { | |
fn prototype() -> City<'a> { | |
City { name: "", country: "" } | |
} | |
fn name(mut self, name: &'a str) -> City { | |
self.name = name; | |
self | |
} | |
fn country(mut self, country: &'a str) -> City { | |
self.country = country; | |
self | |
} | |
} | |
#[test] | |
fn city() { | |
let city = City::prototype(); | |
let berlin = City::prototype().name("Berlin").country("Germany"); | |
assert_eq!(city, City { name: "", country: "" }); | |
assert_eq!(berlin, City { name: "Berlin", country: "Germany" }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment