summaryrefslogtreecommitdiffstats
path: root/src/commit/user.rs
blob: cc4e963a9c101e0827f0ebb92a83e63d8703a535 (plain)
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
#[derive(Debug, Eq, PartialEq)]
pub struct User {
	name: Option<String>,
	email: Option<String>,
}

impl User {
	pub fn new(name: Option<&str>, email: Option<&str>) -> Self {
		User {
			email: email.map(String::from),
			name: name.map(String::from),
		}
	}

	pub fn to_string(&self) -> Option<String> {
		let name = &self.name;
		let email = &self.email;
		match name {
			Some(n) => {
				match email {
					Some(e) => Some(format!("{} <{}>", *n, *e)),
					None => Some(n.to_string()),
				}
			},
			None => {
				match email {
					Some(e) => Some(format!("<{}>", *e)),
					None => None,
				}
			},
		}
	}
}