2024-08-08 21:55:21 +02:00
|
|
|
//! # User
|
2024-09-04 21:37:35 +02:00
|
|
|
//! An user is identified by an UUID, which should never change.
|
|
|
|
//! Each user has an username, which can change but should be unique.
|
2024-08-08 21:55:21 +02:00
|
|
|
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
2024-09-04 21:37:35 +02:00
|
|
|
/// Represents a service user
|
2024-08-08 21:55:21 +02:00
|
|
|
#[derive(Debug, Clone)]
|
2024-10-16 02:46:20 +02:00
|
|
|
#[cfg_attr(any(feature = "py", feature = "py-noabi"), pyo3::pyclass)]
|
2024-09-11 15:45:35 +02:00
|
|
|
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
2024-08-08 21:55:21 +02:00
|
|
|
pub struct User {
|
2024-09-05 01:45:48 +02:00
|
|
|
/// User unique identifier, should never change.
|
2024-08-08 21:55:21 +02:00
|
|
|
pub id: Uuid,
|
2024-09-05 01:45:48 +02:00
|
|
|
/// User name, can change but should be unique.
|
2024-08-22 00:57:24 +02:00
|
|
|
pub name: String,
|
2024-08-08 21:55:21 +02:00
|
|
|
}
|
|
|
|
|
2024-08-22 00:57:24 +02:00
|
|
|
impl From<codemp_proto::common::User> for User {
|
|
|
|
fn from(value: codemp_proto::common::User) -> Self {
|
2024-08-08 21:55:21 +02:00
|
|
|
Self {
|
2024-08-22 00:57:24 +02:00
|
|
|
id: value.id.uuid(),
|
|
|
|
name: value.name,
|
2024-08-08 21:55:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-22 00:57:24 +02:00
|
|
|
impl From<User> for codemp_proto::common::User {
|
2024-08-08 21:55:21 +02:00
|
|
|
fn from(value: User) -> Self {
|
|
|
|
Self {
|
2024-08-22 00:57:24 +02:00
|
|
|
id: value.id.into(),
|
|
|
|
name: value.name,
|
2024-08-08 21:55:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-08-22 00:57:24 +02:00
|
|
|
|
|
|
|
impl PartialEq for User {
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
self.id.eq(&other.id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Eq for User {}
|
|
|
|
|
|
|
|
impl PartialOrd for User {
|
|
|
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
|
|
|
Some(self.id.cmp(&other.id))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Ord for User {
|
|
|
|
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
|
|
|
self.id.cmp(&other.id)
|
|
|
|
}
|
|
|
|
}
|