citadel_types/user/
mod.rs1use serde::{Deserialize, Serialize};
2use std::hash::Hasher;
3use uuid::Uuid;
4
5#[derive(Serialize, Deserialize, Clone, Debug)]
7pub struct MutualPeer {
8 pub parent_icid: u64,
10 pub cid: u64,
12 pub username: Option<String>,
14}
15
16#[derive(Serialize, Deserialize, Clone, Debug)]
18pub struct PeerInfo {
19 pub cid: u64,
21 pub username: String,
23 pub full_name: String,
25}
26
27impl PartialEq for MutualPeer {
28 fn eq(&self, other: &Self) -> bool {
29 self.parent_icid == other.parent_icid
30 && self.cid == other.cid
31 && self.username.as_ref() == other.username.as_ref()
32 }
33}
34
35pub fn username_to_cid(username: &str) -> u64 {
37 let mut hasher = twox_hash::XxHash64::default();
38 hasher.write(username.as_bytes());
39 hasher.finish()
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44pub enum UserIdentifier {
45 ID(u64),
47 Username(String),
49}
50
51impl From<String> for UserIdentifier {
52 fn from(username: String) -> Self {
53 Self::Username(username)
54 }
55}
56
57impl From<&str> for UserIdentifier {
58 fn from(username: &str) -> Self {
59 Self::Username(username.to_string())
60 }
61}
62
63impl From<u64> for UserIdentifier {
64 fn from(cid: u64) -> Self {
65 Self::ID(cid)
66 }
67}
68
69impl From<Uuid> for UserIdentifier {
70 fn from(uuid: Uuid) -> Self {
71 Self::Username(uuid.to_string())
72 }
73}