2023-05-17 09:49:39 +08:00
|
|
|
use flowy_error::ErrorCode;
|
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-05-17 09:49:39 +08:00
|
|
|
pub fn parse(s: String) -> Result<UserId, ErrorCode> {
|
2023-02-13 09:29:49 +08:00
|
|
|
let is_empty_or_whitespace = s.trim().is_empty();
|
|
|
|
if is_empty_or_whitespace {
|
2023-05-17 09:49:39 +08:00
|
|
|
return Err(ErrorCode::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
|
|
|
}
|