21 lines
432 B
Rust
Raw Normal View History

2023-01-30 11:11:19 +08:00
use crate::errors::UserErrorCode;
#[derive(Debug)]
pub struct UserId(pub String);
impl UserId {
2023-01-30 11:11:19 +08:00
pub fn parse(s: String) -> Result<UserId, UserErrorCode> {
let is_empty_or_whitespace = s.trim().is_empty();
if is_empty_or_whitespace {
2023-01-30 11:11:19 +08:00
return Err(UserErrorCode::UserIdInvalid);
}
Ok(Self(s))
}
}
impl AsRef<str> for UserId {
2022-01-23 12:14:00 +08:00
fn as_ref(&self) -> &str {
&self.0
}
}