gix_mailmap/
entry.rs

1use bstr::BStr;
2
3use crate::Entry;
4
5/// Access
6impl<'a> Entry<'a> {
7    /// The name to map to.
8    pub fn new_name(&self) -> Option<&'a BStr> {
9        self.new_name
10    }
11    /// The email map to.
12    pub fn new_email(&self) -> Option<&'a BStr> {
13        self.new_email
14    }
15    /// The name to look for and replace.
16    pub fn old_name(&self) -> Option<&'a BStr> {
17        self.old_name
18    }
19    /// The email to look for and replace.
20    pub fn old_email(&self) -> &'a BStr {
21        self.old_email
22    }
23}
24
25/// Constructors indicating what kind of mapping is created.
26///
27/// Only these combinations of values are valid.
28impl<'a> Entry<'a> {
29    /// An entry that changes the name by an email.
30    pub fn change_name_by_email(proper_name: impl Into<&'a BStr>, commit_email: impl Into<&'a BStr>) -> Self {
31        Entry {
32            new_name: Some(proper_name.into()),
33            old_email: commit_email.into(),
34            ..Default::default()
35        }
36    }
37    /// An entry that changes the email by an email.
38    pub fn change_email_by_email(proper_email: impl Into<&'a BStr>, commit_email: impl Into<&'a BStr>) -> Self {
39        Entry {
40            new_email: Some(proper_email.into()),
41            old_email: commit_email.into(),
42            ..Default::default()
43        }
44    }
45    /// An entry that changes the email by a name and email.
46    pub fn change_email_by_name_and_email(
47        proper_email: impl Into<&'a BStr>,
48        commit_name: impl Into<&'a BStr>,
49        commit_email: impl Into<&'a BStr>,
50    ) -> Self {
51        Entry {
52            new_email: Some(proper_email.into()),
53            old_email: commit_email.into(),
54            old_name: Some(commit_name.into()),
55            ..Default::default()
56        }
57    }
58    /// An entry that changes a name and the email by an email.
59    pub fn change_name_and_email_by_email(
60        proper_name: impl Into<&'a BStr>,
61        proper_email: impl Into<&'a BStr>,
62        commit_email: impl Into<&'a BStr>,
63    ) -> Self {
64        Entry {
65            new_name: Some(proper_name.into()),
66            new_email: Some(proper_email.into()),
67            old_email: commit_email.into(),
68            ..Default::default()
69        }
70    }
71    /// An entry that changes a name and email by a name and email.
72    pub fn change_name_and_email_by_name_and_email(
73        proper_name: impl Into<&'a BStr>,
74        proper_email: impl Into<&'a BStr>,
75        commit_name: impl Into<&'a BStr>,
76        commit_email: impl Into<&'a BStr>,
77    ) -> Self {
78        Entry {
79            new_name: Some(proper_name.into()),
80            new_email: Some(proper_email.into()),
81            old_name: Some(commit_name.into()),
82            old_email: commit_email.into(),
83        }
84    }
85}