1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#[cfg(feature = "json-types")]
use rustc_serialize::json;
#[derive(PartialEq, Debug, Clone, RustcEncodable, RustcDecodable)]
pub struct Address {
address1: String,
address2: Option<String>,
city: String,
state: String,
zip: String,
country: String,
}
impl Address {
pub fn new<S: AsRef<str>>(address1: S,
address2: Option<S>,
city: S,
state: S,
zip: S,
country: S)
-> Address {
Address {
address1: address1.as_ref().to_owned(),
address2: match address2 {
Some(s) => Some(s.as_ref().to_owned()),
None => None,
},
city: city.as_ref().to_owned(),
state: state.as_ref().to_owned(),
zip: zip.as_ref().to_owned(),
country: country.as_ref().to_owned(),
}
}
pub fn get_address1(&self) -> &str {
&self.address1
}
pub fn get_address2(&self) -> Option<&str> {
match self.address2 {
Some(ref addr2) => Some(addr2),
None => None,
}
}
pub fn get_city(&self) -> &str {
&self.city
}
pub fn get_state(&self) -> &str {
&self.state
}
pub fn get_zip(&self) -> &str {
&self.zip
}
pub fn get_country(&self) -> &str {
&self.country
}
}
#[cfg(feature = "json-types")]
impl json::ToJson for Address {
fn to_json(&self) -> json::Json {
let mut object = json::Object::new();
let _ = object.insert(String::from("address1"), self.address1.to_json());
let _ = object.insert(String::from("address2"), self.address2.to_json());
let _ = object.insert(String::from("city"), self.city.to_json());
let _ = object.insert(String::from("state"), self.state.to_json());
let _ = object.insert(String::from("zip"), self.zip.to_json());
let _ = object.insert(String::from("country"), self.country.to_json());
json::Json::Object(object)
}
}