Debian Codegraph @

src/keywords/pattern_properties.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#;
2
3 use craterust-analyzer cargo jsonschema 0.37.4 crate/::{
4 compilerrust-analyzer cargo jsonschema 0.37.4 compiler/,
5 errorrust-analyzer cargo jsonschema 0.37.4 error/::{no_errorrust-analyzer cargo jsonschema 0.37.4 error/no_error()., ErrorIteratorrust-analyzer cargo jsonschema 0.37.4 error/ErrorIterator#, ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#},
6 evaluationrust-analyzer cargo jsonschema 0.37.4 evaluation/::Annotationsrust-analyzer cargo jsonschema 0.37.4 evaluation/Annotations#,
7 keywordsrust-analyzer cargo jsonschema 0.37.4 keywords/::CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#,
8 noderust-analyzer cargo jsonschema 0.37.4 node/::SchemaNoderust-analyzer cargo jsonschema 0.37.4 node/SchemaNode#,
9 optionsrust-analyzer cargo jsonschema 0.37.4 options/::PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#,
10 pathsrust-analyzer cargo jsonschema 0.37.4 paths/::{LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#, Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#},
11 regexrust-analyzer cargo jsonschema 0.37.4 regex/::RegexEnginerust-analyzer cargo jsonschema 0.37.4 regex/RegexEngine#,
12 typesrust-analyzer cargo jsonschema 0.37.4 types/::JsonTyperust-analyzer cargo jsonschema 0.37.4 types/JsonType#,
13 validatorrust-analyzer cargo jsonschema 0.37.4 validator/::{EvaluationResultrust-analyzer cargo jsonschema 0.37.4 validator/EvaluationResult#, Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate#, ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#},
14 };
15 use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::{Maprust-analyzer cargo serde_json 1.0.145 map/Map#, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#};
16
17 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) struct PatternPropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/PatternPropertiesValidator#<R> {
18 patternsrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/PatternPropertiesValidator#patterns.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<R>, SchemaNoderust-analyzer cargo jsonschema 0.37.4 node/SchemaNode#)>,
19 }
20
21 impl<R: RegexEnginerust-analyzer cargo jsonschema 0.37.4 regex/RegexEngine#> Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate# for PatternPropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/PatternPropertiesValidator#<R> {
22 fn is_validrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/impl#[`PatternPropertiesValidator<R>`][Validate]is_valid().(&self, instance: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#) -> bool {
23 if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(item) = instance {
24 for (re, node) in &self.patternsrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/PatternPropertiesValidator#patterns. {
25 for (key, value) in item {
26 if re.is_matchrust-analyzer cargo jsonschema 0.37.4 regex/RegexEngine#is_match().(key).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(false) && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().node.is_validrust-analyzer cargo jsonschema 0.37.4 node/impl#[SchemaNode][Validate]is_valid().(value, ctx) {
27 return false;
28 }
29 }
30 }
31 true
32 } else {
33 true
34 }
35 }
36
37 fn validaterust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/impl#[`PatternPropertiesValidator<R>`][Validate]validate().<'i>(
38 &self,
39 instance: &'i Valuerust-analyzer cargo serde_json 1.0.145 value/Value#,
40 location: &LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#,
41 ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#,
42 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'i>> {
43 if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(item) = instance {
44 for (key, value) in item {
45 for (re, node) in &self.patternsrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/PatternPropertiesValidator#patterns. {
46 if re.is_matchrust-analyzer cargo jsonschema 0.37.4 regex/RegexEngine#is_match().(key).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(false) {
47 node.validaterust-analyzer cargo jsonschema 0.37.4 node/impl#[SchemaNode][Validate]validate().(value, &location.pushrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'a, '_>`]push().(key), ctx)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
48 }
49 }
50 }
51 }
52 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
53 }
54
55 fn iter_errorsrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/impl#[`PatternPropertiesValidator<R>`][Validate]iter_errors().<'i>(
56 &self,
57 instance: &'i Valuerust-analyzer cargo serde_json 1.0.145 value/Value#,
58 location: &LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#,
59 ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#,
60 ) -> ErrorIteratorrust-analyzer cargo jsonschema 0.37.4 error/ErrorIterator#<'i> {
61 if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(item) = instance {
62 let mut errors = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
63 for (re, node) in &self.patternsrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/PatternPropertiesValidator#patterns. {
64 for (key, value) in item {
65 if re.is_matchrust-analyzer cargo jsonschema 0.37.4 regex/RegexEngine#is_match().(key).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(false) {
66 errors.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(node.iter_errorsrust-analyzer cargo jsonschema 0.37.4 node/impl#[SchemaNode][Validate]iter_errors().(value, &location.pushrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'a, '_>`]push().(key.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()), ctx));
67 }
68 }
69 }
70 ErrorIteratorrust-analyzer cargo jsonschema 0.37.4 error/ErrorIterator#::from_iteratorrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ErrorIterator<'a>`]from_iterator().(errors.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().())
71 } else {
72 no_errorrust-analyzer cargo jsonschema 0.37.4 error/no_error().()
73 }
74 }
75
76 fn evaluaterust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/impl#[`PatternPropertiesValidator<R>`][Validate]evaluate().(
77 &self,
78 instance: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#,
79 location: &LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#,
80 ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#,
81 ) -> EvaluationResultrust-analyzer cargo jsonschema 0.37.4 validator/EvaluationResult# {
82 if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(item) = instance {
83 let mut matched_propnames = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(item.lenrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]len().());
84 let mut children = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
85 for (pattern, node) in &self.patternsrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/PatternPropertiesValidator#patterns. {
86 for (key, value) in item {
87 if pattern.is_matchrust-analyzer cargo jsonschema 0.37.4 regex/RegexEngine#is_match().(key).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(false) {
88 matched_propnames.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(key.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().());
89 children.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(node.evaluate_instancerust-analyzer cargo jsonschema 0.37.4 node/impl#[SchemaNode]evaluate_instance().(
90 value,
91 &location.pushrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'a, '_>`]push().(key.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()),
92 ctx,
93 ));
94 }
95 }
96 }
97 let mut result = EvaluationResultrust-analyzer cargo jsonschema 0.37.4 validator/EvaluationResult#::from_childrenrust-analyzer cargo jsonschema 0.37.4 validator/impl#[EvaluationResult]from_children().(children);
98 result.annotaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[EvaluationResult]annotate().(Annotationsrust-analyzer cargo jsonschema 0.37.4 evaluation/Annotations#::newrust-analyzer cargo jsonschema 0.37.4 evaluation/impl#[Annotations]new().(Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::fromrust-analyzer cargo serde_json 1.0.145 value/from/impl#[Value][`From<Vec<T>>`]from().(matched_propnames)));
99 result
100 } else {
101 EvaluationResultrust-analyzer cargo jsonschema 0.37.4 validator/EvaluationResult#::valid_emptyrust-analyzer cargo jsonschema 0.37.4 validator/impl#[EvaluationResult]valid_empty().()
102 }
103 }
104 }
105
106 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) struct SingleValuePatternPropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator#<R> {
107 regexrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator#regex.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<R>,
108 noderust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator#node.: SchemaNoderust-analyzer cargo jsonschema 0.37.4 node/SchemaNode#,
109 }
110
111 impl<R: RegexEnginerust-analyzer cargo jsonschema 0.37.4 regex/RegexEngine#> Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate# for SingleValuePatternPropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator#<R> {
112 fn is_validrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/impl#[`SingleValuePatternPropertiesValidator<R>`][Validate]is_valid().(&self, instance: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#) -> bool {
113 if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(item) = instance {
114 for (key, value) in item {
115 if self.regexrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator#regex..is_matchrust-analyzer cargo jsonschema 0.37.4 regex/RegexEngine#is_match().(key).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(false) && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.noderust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator#node..is_validrust-analyzer cargo jsonschema 0.37.4 node/impl#[SchemaNode][Validate]is_valid().(value, ctx) {
116 return false;
117 }
118 }
119 true
120 } else {
121 true
122 }
123 }
124
125 fn validaterust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/impl#[`SingleValuePatternPropertiesValidator<R>`][Validate]validate().<'i>(
126 &self,
127 instance: &'i Valuerust-analyzer cargo serde_json 1.0.145 value/Value#,
128 location: &LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#,
129 ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#,
130 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'i>> {
131 if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(item) = instance {
132 for (key, value) in item {
133 if self.regexrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator#regex..is_matchrust-analyzer cargo jsonschema 0.37.4 regex/RegexEngine#is_match().(key).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(false) {
134 self.noderust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator#node..validaterust-analyzer cargo jsonschema 0.37.4 node/impl#[SchemaNode][Validate]validate().(value, &location.pushrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'a, '_>`]push().(key), ctx)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
135 }
136 }
137 }
138 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
139 }
140
141 fn iter_errorsrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/impl#[`SingleValuePatternPropertiesValidator<R>`][Validate]iter_errors().<'i>(
142 &self,
143 instance: &'i Valuerust-analyzer cargo serde_json 1.0.145 value/Value#,
144 location: &LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#,
145 ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#,
146 ) -> ErrorIteratorrust-analyzer cargo jsonschema 0.37.4 error/ErrorIterator#<'i> {
147 if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(item) = instance {
148 let mut errors = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
149 for (key, value) in item {
150 if self.regexrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator#regex..is_matchrust-analyzer cargo jsonschema 0.37.4 regex/RegexEngine#is_match().(key).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(false) {
151 errors.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(
152 self.noderust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator#node.
153 .iter_errorsrust-analyzer cargo jsonschema 0.37.4 node/impl#[SchemaNode][Validate]iter_errors().(value, &location.pushrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'a, '_>`]push().(key.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()), ctx),
154 );
155 }
156 }
157 ErrorIteratorrust-analyzer cargo jsonschema 0.37.4 error/ErrorIterator#::from_iteratorrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ErrorIterator<'a>`]from_iterator().(errors.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().())
158 } else {
159 no_errorrust-analyzer cargo jsonschema 0.37.4 error/no_error().()
160 }
161 }
162
163 fn evaluaterust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/impl#[`SingleValuePatternPropertiesValidator<R>`][Validate]evaluate().(
164 &self,
165 instance: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#,
166 location: &LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#,
167 ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#,
168 ) -> EvaluationResultrust-analyzer cargo jsonschema 0.37.4 validator/EvaluationResult# {
169 if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(item) = instance {
170 let mut matched_propnames = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(item.lenrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]len().());
171 let mut children = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
172 for (key, value) in item {
173 if self.regexrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator#regex..is_matchrust-analyzer cargo jsonschema 0.37.4 regex/RegexEngine#is_match().(key).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(false) {
174 matched_propnames.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(key.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().());
175 children.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(self.noderust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator#node..evaluate_instancerust-analyzer cargo jsonschema 0.37.4 node/impl#[SchemaNode]evaluate_instance().(
176 value,
177 &location.pushrust-analyzer cargo jsonschema 0.37.4 paths/impl#[`LazyLocation<'a, '_>`]push().(key.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()),
178 ctx,
179 ));
180 }
181 }
182 let mut result = EvaluationResultrust-analyzer cargo jsonschema 0.37.4 validator/EvaluationResult#::from_childrenrust-analyzer cargo jsonschema 0.37.4 validator/impl#[EvaluationResult]from_children().(children);
183 result.annotaterust-analyzer cargo jsonschema 0.37.4 validator/impl#[EvaluationResult]annotate().(Annotationsrust-analyzer cargo jsonschema 0.37.4 evaluation/Annotations#::newrust-analyzer cargo jsonschema 0.37.4 evaluation/impl#[Annotations]new().(Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::fromrust-analyzer cargo serde_json 1.0.145 value/from/impl#[Value][`From<Vec<T>>`]from().(matched_propnames)));
184 result
185 } else {
186 EvaluationResultrust-analyzer cargo jsonschema 0.37.4 validator/EvaluationResult#::valid_emptyrust-analyzer cargo jsonschema 0.37.4 validator/impl#[EvaluationResult]valid_empty().()
187 }
188 }
189 }
190
191 #[inline]
192 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compilerust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/compile().<'a>(
193 ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#,
194 parent: &'a Maprust-analyzer cargo serde_json 1.0.145 map/Map#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#>,
195 schema: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#,
196 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'a>> {
197 if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(
198 parent.getrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]get().("additionalProperties"),
199 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Boolrust-analyzer cargo serde_json 1.0.145 value/Value#Bool#(false) | Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(_))
200 ) {
201 // This type of `additionalProperties` validator handles `patternProperties` logic
202 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
203 }
204
205 let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(map) = schema else {
206 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::single_type_errorrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]single_type_error().(
207 Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().(),
208 ctx.locationrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]location().().clonerust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][Clone]clone().(),
209 schema,
210 JsonTyperust-analyzer cargo jsonschema 0.37.4 types/JsonType#::Objectrust-analyzer cargo jsonschema 0.37.4 types/JsonType#Object#,
211 )));
212 };
213 let ctx = ctx.new_at_locationrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]new_at_location().("patternProperties");
214 let result = match ctx.configrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]config().().pattern_optionsrust-analyzer cargo jsonschema 0.37.4 options/impl#[ValidationOptions]pattern_options().() {
215 PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#::FancyRegexrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#FancyRegex# { .. } => {
216 compile_pattern_entriesrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/compile_pattern_entries().(&ctx, map, |pctx, pattern, subschema| {
217 pctx.get_or_compile_regexrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]get_or_compile_regex().(pattern)
218 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|()| invalid_regexrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/invalid_regex().(pctx, subschema))
219 })
220 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|patterns| {
221 build_validator_from_entriesrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/build_validator_from_entries().(patterns, |regex, node| {
222 Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(SingleValuePatternPropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator# { regexrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator#regex., noderust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator#node. })
223 as Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate#>
224 })
225 })
226 }
227 PatternEngineOptionsrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#::Regexrust-analyzer cargo jsonschema 0.37.4 options/PatternEngineOptions#Regex# { .. } => {
228 compile_pattern_entriesrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/compile_pattern_entries().(&ctx, map, |pctx, pattern, subschema| {
229 pctx.get_or_compile_standard_regexrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]get_or_compile_standard_regex().(pattern)
230 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|()| invalid_regexrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/invalid_regex().(pctx, subschema))
231 })
232 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|patterns| {
233 build_validator_from_entriesrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/build_validator_from_entries().(patterns, |regex, node| {
234 Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(SingleValuePatternPropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator# { regexrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator#regex., noderust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/SingleValuePatternPropertiesValidator#node. })
235 as Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate#>
236 })
237 })
238 }
239 };
240 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(result)
241 }
242
243 fn invalid_regexrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/invalid_regex().<'a>(ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#, schema: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#) -> ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'a> {
244 ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::formatrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]format().(Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#::newrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]new().(), ctx.locationrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]location().().clonerust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][Clone]clone().(), schema, "regex")
245 }
246
247 /// Compile every `(pattern, subschema)` pair into `(regex, node)` tuples.
248 fn compile_pattern_entriesrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/compile_pattern_entries().<'a, R, F>(
249 ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#,
250 map: &'a Maprust-analyzer cargo serde_json 1.0.145 map/Map#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#>,
251 mut compile_regex: F,
252 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<R>, SchemaNoderust-analyzer cargo jsonschema 0.37.4 node/SchemaNode#)>, ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'a>>
253 where
254 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#, &str, &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<R>, ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'a>>,
255 {
256 let mut patterns = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(map.lenrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]len().());
257 for (pattern, subschema) in map {
258 let pctx = ctx.new_at_locationrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]new_at_location().(pattern.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().());
259 let regex = compile_regex(&pctx, pattern, subschema)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
260 let node = compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::compilerust-analyzer cargo jsonschema 0.37.4 compiler/compile().(&pctx, pctx.as_resource_refrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]as_resource_ref().(subschema))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
261 patterns.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((regex, node));
262 }
263 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(patterns)
264 }
265
266 /// Pick the optimal validator representation for the compiled pattern entries.
267 fn build_validator_from_entriesrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/build_validator_from_entries().<R>(
268 mut entries: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<R>, SchemaNoderust-analyzer cargo jsonschema 0.37.4 node/SchemaNode#)>,
269 single_factory: impl FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<R>, SchemaNoderust-analyzer cargo jsonschema 0.37.4 node/SchemaNode#) -> Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate#>,
270 ) -> Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate#>
271 where
272 R: RegexEnginerust-analyzer cargo jsonschema 0.37.4 regex/RegexEngine# + 'static,
273 {
274 if entries.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 {
275 let (regex, node) = entries.poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("len checked");
276 single_factory(regex, node)
277 } else {
278 Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(PatternPropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/PatternPropertiesValidator# { patternsrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/PatternPropertiesValidator#patterns.: entries })
279 }
280 }
281
282 #[cfg(test)]
283 mod testsrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/tests/ {
284 use craterust-analyzer cargo jsonschema 0.37.4 crate/::tests_utilrust-analyzer cargo jsonschema 0.37.4 tests_util/;
285 use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::{jsonrust-analyzer cargo serde_json 1.0.145 macros/json!, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#};
286 use test_caserust-analyzer cargo test-case 3.3.1 crate/::test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:;
287
288 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"patternProperties": {"^f": {"type": "string"}}}), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"f": 42}), "/patternProperties/^f/type")]
289 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"patternProperties": {"^f": {"type": "string"}, "^x": {"type": "string"}}}), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"f": 42}), "/patternProperties/^f/type")]
290 fn locationrust-analyzer cargo jsonschema 0.37.4 keywords/pattern_properties/tests/location().(schema: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, instance: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, expected: &str) {
291 tests_utilrust-analyzer cargo jsonschema 0.37.4 tests_util/::assert_schema_locationrust-analyzer cargo jsonschema 0.37.4 tests_util/assert_schema_location().(schema, instance, expected);
292 }
293 }