user_id.rs 420 B

1234567891011121314151617181920
  1. use crate::errors::ErrorCode;
  2. #[derive(Debug)]
  3. pub struct UserId(pub String);
  4. impl UserId {
  5. pub fn parse(s: String) -> Result<UserId, ErrorCode> {
  6. let is_empty_or_whitespace = s.trim().is_empty();
  7. if is_empty_or_whitespace {
  8. return Err(ErrorCode::UserIdInvalid);
  9. }
  10. Ok(Self(s))
  11. }
  12. }
  13. impl AsRef<str> for UserId {
  14. fn as_ref(&self) -> &str {
  15. &self.0
  16. }
  17. }