| 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 MaxLengthValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/max_length/MaxLengthValidator# { |
| 13 | limitrust-analyzer cargo jsonschema 0.37.4 keywords/max_length/MaxLengthValidator#limit.: u64, |
| 14 | locationrust-analyzer cargo jsonschema 0.37.4 keywords/max_length/MaxLengthValidator#location.: Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#, |
| 15 | } |
| 16 | |
| 17 | impl MaxLengthValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/max_length/MaxLengthValidator# { |
| 18 | #[inline] |
| 19 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compilerust-analyzer cargo jsonschema 0.37.4 keywords/max_length/impl#[MaxLengthValidator]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().(MaxLengthValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/max_length/MaxLengthValidator# { limitrust-analyzer cargo jsonschema 0.37.4 keywords/max_length/MaxLengthValidator#limit., locationrust-analyzer cargo jsonschema 0.37.4 keywords/max_length/MaxLengthValidator#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().(MaxLengthValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/max_length/MaxLengthValidator# { |
| 32 | // NOTE: Imprecise cast as big integers are not supported yet |
| 33 | limitrust-analyzer cargo jsonschema 0.37.4 keywords/max_length/MaxLengthValidator#limit.: limit as u64, |
| 34 | locationrust-analyzer cargo jsonschema 0.37.4 keywords/max_length/MaxLengthValidator#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 MaxLengthValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/max_length/MaxLengthValidator# { |
| 44 | fn is_validrust-analyzer cargo jsonschema 0.37.4 keywords/max_length/impl#[MaxLengthValidator][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#::Stringrust-analyzer cargo serde_json 1.0.145 value/Value#String#(item) = instance { |
| 46 | if (bytecountrust-analyzer cargo bytecount 0.6.9 crate/::num_charsrust-analyzer cargo bytecount 0.6.9 num_chars().(item.as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().()) 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_length/MaxLengthValidator#limit. { |
| 47 | return false; |
| 48 | } |
| 49 | } |
| 50 | true |
| 51 | } |
| 52 | |
| 53 | fn validaterust-analyzer cargo jsonschema 0.37.4 keywords/max_length/impl#[MaxLengthValidator][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#::Stringrust-analyzer cargo serde_json 1.0.145 value/Value#String#(item) = instance { |
| 60 | if (bytecountrust-analyzer cargo bytecount 0.6.9 crate/::num_charsrust-analyzer cargo bytecount 0.6.9 num_chars().(item.as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().()) 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_length/MaxLengthValidator#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_lengthrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]max_length().( |
| 62 | self.locationrust-analyzer cargo jsonschema 0.37.4 keywords/max_length/MaxLengthValidator#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_length/MaxLengthValidator#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_length/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().("maxLength"); |
| 80 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MaxLengthValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/max_length/MaxLengthValidator#::compilerust-analyzer cargo jsonschema 0.37.4 keywords/max_length/impl#[MaxLengthValidator]compile().(ctx, schema, location)) |
| 81 | } |
| 82 | |
| 83 | #[cfg(test)] |
| 84 | mod testsrust-analyzer cargo jsonschema 0.37.4 keywords/max_length/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_length/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().(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"maxLength": 1}), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!("ab"), "/maxLength"); |
| 91 | } |
| 92 | } |