1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use serde_json::{Value};
use regex;

use super::super::errors;

impl super::Validator for regex::Regex {
    fn validate(&self, val: &Value, path: &str) -> super::ValidatorResult {

        let string = strict_process!(val.as_str(), path, "The value must be a string");

        if self.is_match(string) {
            Ok(())
        } else {
            Err(vec![
                Box::new(errors::WrongValue {
                    path: path.to_string(),
                    detail: Some("Value is not matched by required pattern".to_string())
                })
            ])
        }
    }
}