valico/json_schema/validators/
enum_.rs
1use serde_json::{Value};
2
3use super::super::errors;
4use super::super::scope;
5
6#[allow(missing_copy_implementations)]
7pub struct Enum {
8 pub items: Vec<Value>
9}
10
11impl super::Validator for Enum {
12 fn validate(&self, val: &Value, path: &str, _scope: &scope::Scope) -> super::ValidationState {
13 let mut state = super::ValidationState::new();
14
15 let mut contains = false;
16 for value in self.items.iter() {
17 if val == value {
18 contains = true;
19 break;
20 }
21 }
22
23 if !contains {
24 state.errors.push(Box::new(
25 errors::Enum {
26 path: path.to_string()
27 }
28 ))
29 }
30
31 state
32 }
33}