parser.rs 318 B

1234567891011121314151617
  1. #[derive(Debug)]
  2. pub struct NotEmptyStr(pub String);
  3. impl NotEmptyStr {
  4. pub fn parse(s: String) -> Result<Self, String> {
  5. if s.trim().is_empty() {
  6. return Err("Input string is empty".to_owned());
  7. }
  8. Ok(Self(s))
  9. }
  10. }
  11. impl AsRef<str> for NotEmptyStr {
  12. fn as_ref(&self) -> &str {
  13. &self.0
  14. }
  15. }