summaryrefslogtreecommitdiff
path: root/src/user/id.rs
blob: ceb310a8bd362852c1a18dc7c0a29e049b48fbea (plain)
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
use crate::login;

// Stable identifier for a User. Prefixed with `U`. Users created before March, 2025 may have an `L`
// prefix, instead.
pub type Id = crate::id::Id<User>;

// Login IDs and user IDs are typewise-distinct as they identify things in different namespaces, but
// in practice a login and its associated user _must_ have IDs that encode to the same value. The
// two ID types are made interconvertible (via `From`) for this purpose.
impl From<login::Id> for Id {
    fn from(login: login::Id) -> Self {
        Self::from(String::from(login))
    }
}

impl PartialEq<login::Id> for Id {
    fn eq(&self, other: &login::Id) -> bool {
        self.as_str().eq(other.as_str())
    }
}

#[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct User;

impl crate::id::Prefix for User {
    fn prefix(&self) -> &'static str {
        "U"
    }
}