32 lines
698 B
Rust
32 lines
698 B
Rust
use super::contextualize::Contextualize;
|
|
use super::id::{IdError, validate_id};
|
|
|
|
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
|
pub struct UserId(String);
|
|
|
|
impl UserId {
|
|
pub const MAX_BYTES: usize = 128;
|
|
|
|
pub fn new(value: impl Into<String>) -> Result<Self, IdError> {
|
|
let value = value.into();
|
|
validate_id(&value, Self::MAX_BYTES, IdError::User)?;
|
|
Ok(Self(value))
|
|
}
|
|
|
|
pub fn as_str(&self) -> &str {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct User {
|
|
pub id: UserId,
|
|
pub display_name: String,
|
|
}
|
|
|
|
impl Contextualize for User {
|
|
fn render_context(&self) -> String {
|
|
format!("User: {}", self.display_name)
|
|
}
|
|
}
|