| 1 | use craterust-analyzer cargo jsonschema 0.37.4 crate/::{ |
| 2 | 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#}, |
| 3 | threadrust-analyzer cargo jsonschema 0.37.4 thread/::ThreadBoundrust-analyzer cargo jsonschema 0.37.4 thread/ThreadBound#, |
| 4 | 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#}, |
| 5 | ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#, |
| 6 | }; |
| 7 | 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#}; |
| 8 | |
| 9 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) struct CustomKeywordrust-analyzer cargo jsonschema 0.37.4 keywords/custom/CustomKeyword# { |
| 10 | innerrust-analyzer cargo jsonschema 0.37.4 keywords/custom/CustomKeyword#inner.: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Keywordrust-analyzer cargo jsonschema 0.37.4 keywords/custom/Keyword#>, |
| 11 | } |
| 12 | |
| 13 | impl CustomKeywordrust-analyzer cargo jsonschema 0.37.4 keywords/custom/CustomKeyword# { |
| 14 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn newrust-analyzer cargo jsonschema 0.37.4 keywords/custom/impl#[CustomKeyword]new().(inner: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Keywordrust-analyzer cargo jsonschema 0.37.4 keywords/custom/Keyword#>) -> Selfrust-analyzer cargo jsonschema 0.37.4 keywords/custom/impl#[CustomKeyword] { |
| 15 | Selfrust-analyzer cargo jsonschema 0.37.4 keywords/custom/impl#[CustomKeyword] { innerrust-analyzer cargo jsonschema 0.37.4 keywords/custom/CustomKeyword#inner. } |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | impl Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate# for CustomKeywordrust-analyzer cargo jsonschema 0.37.4 keywords/custom/CustomKeyword# { |
| 20 | fn validaterust-analyzer cargo jsonschema 0.37.4 keywords/custom/impl#[CustomKeyword][Validate]validate().<'i>( |
| 21 | &self, |
| 22 | instance: &'i Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 23 | location: &LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#, |
| 24 | _ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#, |
| 25 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'i>> { |
| 26 | self.innerrust-analyzer cargo jsonschema 0.37.4 keywords/custom/CustomKeyword#inner..validaterust-analyzer cargo jsonschema 0.37.4 keywords/custom/Keyword#validate().(instance, location) |
| 27 | } |
| 28 | |
| 29 | fn is_validrust-analyzer cargo jsonschema 0.37.4 keywords/custom/impl#[CustomKeyword][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 { |
| 30 | self.innerrust-analyzer cargo jsonschema 0.37.4 keywords/custom/CustomKeyword#inner..is_validrust-analyzer cargo jsonschema 0.37.4 keywords/custom/Keyword#is_valid().(instance) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | /// Trait that allows implementing custom validation for keywords. |
| 35 | pub trait Keywordrust-analyzer cargo jsonschema 0.37.4 keywords/custom/Keyword#: ThreadBoundrust-analyzer cargo jsonschema 0.37.4 thread/ThreadBound# { |
| 36 | /// Validate instance according to a custom specification. |
| 37 | /// |
| 38 | /// A custom keyword validator may be used when a validation that cannot be |
| 39 | /// easily or efficiently expressed in JSON schema. |
| 40 | /// |
| 41 | /// The custom validation is applied in addition to the JSON schema validation. |
| 42 | /// |
| 43 | /// # Errors |
| 44 | /// |
| 45 | /// Returns an error describing why `instance` violates the custom keyword semantics. |
| 46 | fn validaterust-analyzer cargo jsonschema 0.37.4 keywords/custom/Keyword#validate().<'i>( |
| 47 | &self, |
| 48 | instance: &'i Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 49 | location: &LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#, |
| 50 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'i>>; |
| 51 | /// Validate instance and return a boolean result. |
| 52 | /// |
| 53 | /// Could be potentilly faster than [`Keyword::validate`] method. |
| 54 | fn is_validrust-analyzer cargo jsonschema 0.37.4 keywords/custom/Keyword#is_valid().(&self, instance: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#) -> bool; |
| 55 | } |
| 56 | |
| 57 | pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) trait KeywordFactoryrust-analyzer cargo jsonschema 0.37.4 keywords/custom/KeywordFactory#: ThreadBoundrust-analyzer cargo jsonschema 0.37.4 thread/ThreadBound# { |
| 58 | fn initrust-analyzer cargo jsonschema 0.37.4 keywords/custom/KeywordFactory#init().<'a>( |
| 59 | &self, |
| 60 | 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#>, |
| 61 | schema: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 62 | path: Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#, |
| 63 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Keywordrust-analyzer cargo jsonschema 0.37.4 keywords/custom/Keyword#>, ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'a>>; |
| 64 | } |
| 65 | |
| 66 | impl<F> KeywordFactoryrust-analyzer cargo jsonschema 0.37.4 keywords/custom/KeywordFactory# for F |
| 67 | where |
| 68 | F: for<'a> Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#( |
| 69 | &'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#>, |
| 70 | &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 71 | Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#, |
| 72 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Keywordrust-analyzer cargo jsonschema 0.37.4 keywords/custom/Keyword#>, ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'a>> |
| 73 | + ThreadBoundrust-analyzer cargo jsonschema 0.37.4 thread/ThreadBound#, |
| 74 | { |
| 75 | fn initrust-analyzer cargo jsonschema 0.37.4 keywords/custom/impl#[F][KeywordFactory]init().<'a>( |
| 76 | &self, |
| 77 | 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#>, |
| 78 | schema: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, |
| 79 | path: Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#, |
| 80 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Keywordrust-analyzer cargo jsonschema 0.37.4 keywords/custom/Keyword#>, ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'a>> { |
| 81 | self(parent, schema, path) |
| 82 | } |
| 83 | } |