valico/json_schema/validators/
const_.rs1use serde_json::Value;
2
3use super::super::errors;
4use super::super::helpers::is_matching;
5use super::super::scope;
6
7#[allow(missing_copy_implementations)]
8pub struct Const {
9 pub item: Value,
10}
11
12impl super::Validator for Const {
13 fn validate(
14 &self,
15 val: &Value,
16 path: &str,
17 _scope: &scope::Scope,
18 _: &super::ValidationState,
19 ) -> super::ValidationState {
20 let mut state = super::ValidationState::new();
21
22 if !is_matching(&self.item, val) {
23 state.errors.push(Box::new(errors::Const {
24 path: path.to_string(),
25 }))
26 } else {
27 state.evaluated.insert(path.to_owned());
28 }
29
30 state
31 }
32}