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
use serde::{Deserialize, Serialize};

#[derive(Debug, Default)]
pub struct CredentialsBuilder {
    pub credentials: Credentials,
}

#[derive(Clone, Debug, Default)]
pub struct Credentials(pub Vec<Credential>);

#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct Credential {
    email: String,
    password: String,
}

impl CredentialsBuilder {
    const fn new() -> Self {
        Self { credentials: Credentials(Vec::new()) }
    }

    #[must_use]
    pub fn add_credential(mut self, email: String, password: String) -> Self {
        self.credentials.0.push(Credential { email, password });
        self
    }

    #[must_use]
    pub fn build(self) -> Credentials {
        self.credentials
    }
}

impl Credential {
    #[must_use]
    pub fn email(&self) -> &str {
        &self.email
    }

    #[must_use]
    pub fn password(&self) -> &str {
        &self.password
    }
}

impl Credentials {
    #[must_use]
    pub const fn builder() -> CredentialsBuilder {
        CredentialsBuilder::new()
    }

    #[must_use]
    pub const fn empty() -> Self {
        Self(Vec::new())
    }
}