Skip to main content

ephemeris_release/
account.rs

1//! The identity a release acts as.
2
3use std::fmt;
4
5use facet::Facet;
6
7/// A field of an [`Account`].
8#[derive(Clone, Copy, Debug, Eq, PartialEq)]
9pub enum Field {
10    /// The registry login name.
11    Login,
12    /// The author name.
13    Name,
14    /// The author email.
15    Email,
16}
17
18impl fmt::Display for Field {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        f.write_str(match self {
21            Self::Login => "login",
22            Self::Name => "name",
23            Self::Email => "email",
24        })
25    }
26}
27
28/// Who commits, tags and logs in during a release.
29///
30/// The state document carries expressions. The command line evaluates them
31/// into text.
32#[derive(Clone, Debug, Eq, Facet, PartialEq)]
33#[facet(deny_unknown_fields)]
34pub struct Account<V> {
35    /// The registry login name, when the release logs in to a registry.
36    #[facet(default)]
37    pub login: Option<V>,
38    /// The name of commit authors and tag taggers.
39    pub name: V,
40    /// The email of commit authors and tag taggers.
41    pub email: V,
42}
43
44impl Account<String> {
45    /// The commit author and tagger of this account.
46    #[must_use]
47    pub fn author(&self) -> Author<'_> {
48        Author {
49            name: &self.name,
50            email: &self.email,
51        }
52    }
53}
54
55/// The name and email on a commit or tag.
56#[derive(Clone, Copy, Debug, Eq, PartialEq)]
57pub struct Author<'a> {
58    /// The name.
59    pub name: &'a str,
60    /// The email.
61    pub email: &'a str,
62}