Debian Codegraph @

src/keywords/max_properties.rs

raw symbols SCIP
1 #![allow(clippy::float_cmp, clippy::cast_sign_loss)]
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/::ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#,
6 keywordsrust-analyzer cargo jsonschema 0.37.4 keywords/::{helpersrust-analyzer cargo jsonschema 0.37.4 keywords/helpers/::fail_on_non_positive_integerrust-analyzer cargo jsonschema 0.37.4 keywords/helpers/fail_on_non_positive_integer()., CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#},
7 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#},
8 validatorrust-analyzer cargo jsonschema 0.37.4 validator/::{Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate#, ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#},
9 };
10 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#};
11
12 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) struct MaxPropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/MaxPropertiesValidator# {
13 limitrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/MaxPropertiesValidator#limit.: u64,
14 locationrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/MaxPropertiesValidator#location.: Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#,
15 }
16
17 impl MaxPropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/MaxPropertiesValidator# {
18 #[inline]
19 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compilerust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/impl#[MaxPropertiesValidator]compile().<'a>(
20 ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#,
21 schema: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#,
22 location: Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#,
23 ) -> CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'a> {
24 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(limit) = schema.as_u64rust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_u64().() {
25 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(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().(MaxPropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/MaxPropertiesValidator# { limitrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/MaxPropertiesValidator#limit., locationrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/MaxPropertiesValidator#location. }));
26 }
27 if ctx.supports_integer_valued_numbersrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]supports_integer_valued_numbers().() {
28 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(limit) = schema.as_f64rust-analyzer cargo serde_json 1.0.145 value/impl#[Value]as_f64().() {
29 if limit.truncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f64/impl#[f64]trunc().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq().limit {
30 #[allow(clippy::cast_possible_truncation)]
31 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(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().(MaxPropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/MaxPropertiesValidator# {
32 // NOTE: Imprecise cast as big integers are not supported yet
33 limitrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/MaxPropertiesValidator#limit.: limit as u64,
34 locationrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/MaxPropertiesValidator#location.,
35 }));
36 }
37 }
38 }
39 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(fail_on_non_positive_integerrust-analyzer cargo jsonschema 0.37.4 keywords/helpers/fail_on_non_positive_integer().(schema, location))
40 }
41 }
42
43 impl Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate# for MaxPropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/MaxPropertiesValidator# {
44 fn is_validrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/impl#[MaxPropertiesValidator][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 {
45 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 {
46 if (item.lenrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]len().() as u64) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().self.limitrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/MaxPropertiesValidator#limit. {
47 return false;
48 }
49 }
50 true
51 }
52
53 fn validaterust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/impl#[MaxPropertiesValidator][Validate]validate().<'i>(
54 &self,
55 instance: &'i Valuerust-analyzer cargo serde_json 1.0.145 value/Value#,
56 location: &LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#,
57 _ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#,
58 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'i>> {
59 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 {
60 if (item.lenrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]len().() as u64) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().self.limitrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/MaxPropertiesValidator#limit. {
61 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::max_propertiesrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]max_properties().(
62 self.locationrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/MaxPropertiesValidator#location..clonerust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][Clone]clone().(),
63 location.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
64 instance,
65 self.limitrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/MaxPropertiesValidator#limit.,
66 ));
67 }
68 }
69 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
70 }
71 }
72
73 #[inline]
74 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compilerust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/compile().<'a>(
75 ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#,
76 _: &'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#>,
77 schema: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#,
78 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'a>> {
79 let location = ctx.locationrust-analyzer cargo jsonschema 0.37.4 compiler/impl#[`Context<'a>`]location().().joinrust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location]join().("maxProperties");
80 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MaxPropertiesValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/MaxPropertiesValidator#::compilerust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/impl#[MaxPropertiesValidator]compile().(ctx, schema, location))
81 }
82
83 #[cfg(test)]
84 mod testsrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/tests/ {
85 use craterust-analyzer cargo jsonschema 0.37.4 crate/::tests_utilrust-analyzer cargo jsonschema 0.37.4 tests_util/;
86 use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::jsonrust-analyzer cargo serde_json 1.0.145 macros/json!;
87
88 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
89 fn locationrust-analyzer cargo jsonschema 0.37.4 keywords/max_properties/tests/location().() {
90 tests_utilrust-analyzer cargo jsonschema 0.37.4 tests_util/::assert_schema_locationrust-analyzer cargo jsonschema 0.37.4 tests_util/assert_schema_location().(
91 &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"maxProperties": 1}),
92 &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"a": 1, "b": 2}),
93 "/maxProperties",
94 );
95 }
96 }