Skip to main content

gonzalo_core/
identity.rs

1//! Contributor identity attached to every write.
2
3use serde::{Deserialize, Serialize};
4
5/// Who made a change. In local mode this is a configured local identity;
6/// in daemon mode the server authenticates it.
7#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
8pub struct Identity {
9    pub id: String,
10    pub display: Option<String>,
11}
12
13impl Identity {
14    pub fn new(id: impl Into<String>) -> Self {
15        Self {
16            id: id.into(),
17            display: None,
18        }
19    }
20}
21
22#[cfg(test)]
23mod tests {
24    use super::*;
25
26    #[test]
27    fn new_sets_id_and_no_display() {
28        let i = Identity::new("john");
29        assert_eq!(i.id, "john");
30        assert_eq!(i.display, None);
31    }
32}