use serde::{Deserialize, Serialize};
use std::hash::Hasher;
use uuid::Uuid;
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct MutualPeer {
pub parent_icid: u64,
pub cid: u64,
pub username: Option<String>,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct PeerInfo {
pub cid: u64,
pub username: String,
pub full_name: String,
}
impl PartialEq for MutualPeer {
fn eq(&self, other: &Self) -> bool {
self.parent_icid == other.parent_icid
&& self.cid == other.cid
&& self.username.as_ref() == other.username.as_ref()
}
}
pub fn username_to_cid(username: &str) -> u64 {
let mut hasher = twox_hash::XxHash64::default();
hasher.write(username.as_bytes());
hasher.finish()
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum UserIdentifier {
ID(u64),
Username(String),
}
impl From<String> for UserIdentifier {
fn from(username: String) -> Self {
Self::Username(username)
}
}
impl From<&str> for UserIdentifier {
fn from(username: &str) -> Self {
Self::Username(username.to_string())
}
}
impl From<u64> for UserIdentifier {
fn from(cid: u64) -> Self {
Self::ID(cid)
}
}
impl From<Uuid> for UserIdentifier {
fn from(uuid: Uuid) -> Self {
Self::Username(uuid.to_string())
}
}