object_id.rs 375 B

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