json_matcher/
uuid_matcher.rs

1use crate::{JsonMatcher, JsonMatcherError};
2
3pub struct UuidMatcher;
4
5impl Default for UuidMatcher {
6    fn default() -> Self {
7        Self::new()
8    }
9}
10
11impl UuidMatcher {
12    pub fn new() -> Self {
13        Self
14    }
15}
16
17impl JsonMatcher for UuidMatcher {
18    fn json_matches(&self, value: &serde_json::Value) -> Vec<JsonMatcherError> {
19        match value.as_str() {
20            Some(s) if s.len() == 36 && s.chars().filter(|&c| c == '-').count() == 4 => vec![],
21            Some(_) => vec![JsonMatcherError::at_root("Expected valid UUID format")],
22            None => vec![JsonMatcherError::at_root("Expected string for UUID")],
23        }
24    }
25}