hoprd_db_entity/
types.rs

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
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Formatter};

/// Represents an alias
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Alias {
    pub peer_id: String,
    pub alias: String,
}

impl Alias {
    pub fn new(peer_id: String, alias: String) -> Self {
        Self { peer_id, alias }
    }
}

impl Display for Alias {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        write!(f, "{}: {}", self.peer_id, self.alias)
    }
}

impl From<crate::codegen::sqlite::aliases::Model> for Alias {
    fn from(value: crate::codegen::sqlite::aliases::Model) -> Self {
        Alias::new(value.peer_id, value.alias)
    }
}