2023-01-30 11:11:19 +08:00
|
|
|
use crate::errors::UserErrorCode;
|
2021-11-07 21:45:18 +08:00
|
|
|
|
2021-07-11 15:33:19 +08:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct UserId(pub String);
|
|
|
|
|
|
|
|
impl UserId {
|
2023-02-13 09:29:49 +08:00
|
|
|
pub fn parse(s: String) -> Result<UserId, UserErrorCode> {
|
|
|
|
let is_empty_or_whitespace = s.trim().is_empty();
|
|
|
|
if is_empty_or_whitespace {
|
|
|
|
return Err(UserErrorCode::UserIdInvalid);
|
2021-07-11 15:33:19 +08:00
|
|
|
}
|
2023-02-13 09:29:49 +08:00
|
|
|
Ok(Self(s))
|
|
|
|
}
|
2021-07-11 15:33:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl AsRef<str> for UserId {
|
2023-02-13 09:29:49 +08:00
|
|
|
fn as_ref(&self) -> &str {
|
|
|
|
&self.0
|
|
|
|
}
|
2021-07-11 15:33:19 +08:00
|
|
|
}
|