parse.rs 475 B

1234567891011121314151617181920212223
  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. #[derive(Debug)]
  12. pub struct NotEmptyVec<T>(pub Vec<T>);
  13. impl<T> NotEmptyVec<T> {
  14. pub fn parse(v: Vec<T>) -> Result<Self, String> {
  15. if v.is_empty() {
  16. return Err("Input vector is empty".to_owned());
  17. }
  18. Ok(Self(v))
  19. }
  20. }