Skip to content

Instantly share code, notes, and snippets.

@pzol
Last active August 29, 2015 14:07
Show Gist options
  • Save pzol/1ac9c4cf3ddd6bed46b8 to your computer and use it in GitHub Desktop.
Save pzol/1ac9c4cf3ddd6bed46b8 to your computer and use it in GitHub Desktop.
#[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