valico/json_schema/validators/
pattern.rs
1use regex;
2use serde_json::{Value};
3
4use super::super::errors;
5use super::super::scope;
6
7#[allow(missing_copy_implementations)]
8pub struct Pattern {
9 pub regex: regex::Regex
10}
11
12impl super::Validator for Pattern {
13 fn validate(&self, val: &Value, path: &str, _scope: &scope::Scope) -> super::ValidationState {
14 let string = nonstrict_process!(val.as_str(), path);
15
16 if self.regex.is_match(string) {
17 super::ValidationState::new()
18 } else {
19 val_error!(
20 errors::Pattern {
21 path: path.to_string()
22 }
23 )
24 }
25 }
26}