git_bug/entities/identity/snapshot/
mod.rs1use std::fmt::Display;
14
15use url::Url;
16
17use super::Identity;
18use crate::replica::entity::snapshot::Snapshot;
19
20pub mod history_step;
21pub mod timeline;
22
23impl Snapshot<Identity> {
24 #[must_use]
26 #[allow(clippy::missing_panics_doc)]
28 pub fn name(&self) -> &str {
29 &self
30 .timeline()
31 .name_history()
32 .last()
33 .expect("This is mandated by the crate op")
34 .name
35 }
36
37 #[must_use]
39 pub fn email(&self) -> Option<&str> {
40 self.timeline()
41 .email_history()
42 .last()
43 .map(|item| item.email.as_str())
44 }
45
46 #[must_use]
48 pub fn login_name(&self) -> Option<&str> {
49 self.timeline()
50 .login_name_history()
51 .last()
52 .map(|item| item.login_name.as_str())
53 }
54
55 #[must_use]
57 pub fn avatar_url(&self) -> Option<&Url> {
58 self.timeline()
59 .avatar_url_history()
60 .last()
61 .map(|item| &item.avatar_url)
62 }
63
64 #[must_use]
68 pub fn metadata(&self) -> Option<impl Iterator<Item = &(String, String)>> {
69 self.timeline()
70 .metadata_history()
71 .last()
72 .map(|item| item.metadata.iter())
73 }
74}
75
76impl Display for Snapshot<Identity> {
77 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
78 match (self.email(), self.login_name()) {
79 (None, None) => f.write_str(self.name()),
80 (None, Some(login)) => write!(f, "{} ({login})", self.name()),
81 (Some(email), None) => write!(f, "{} <{email}>", self.name()),
82 (Some(email), Some(_login)) => write!(f, "{} <{email}>", self.name()),
83 }
84 }
85}