Debian Codegraph @

src/keywords/unique_items.rs

raw symbols SCIP
1 use craterust-analyzer cargo jsonschema 0.37.4 crate/::{
2 compilerrust-analyzer cargo jsonschema 0.37.4 compiler/,
3 errorrust-analyzer cargo jsonschema 0.37.4 error/::ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#,
4 extrust-analyzer cargo jsonschema 0.37.4 ext/::cmprust-analyzer cargo jsonschema 0.37.4 ext/cmp/,
5 keywordsrust-analyzer cargo jsonschema 0.37.4 keywords/::CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#,
6 pathsrust-analyzer cargo jsonschema 0.37.4 paths/::Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#,
7 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#},
8 };
9 use ahashrust-analyzer cargo ahash 0.8.12 crate/::{AHashSetrust-analyzer cargo ahash 0.8.12 hash_set/AHashSet#, AHasherrust-analyzer cargo ahash 0.8.12 fallback_hash/AHasher#};
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 use craterust-analyzer cargo jsonschema 0.37.4 crate/::pathsrust-analyzer cargo jsonschema 0.37.4 paths/::LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#;
13 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::{Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#, Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#};
14
15 // Based on implementation proposed by Sven Marnach:
16 // https://stackoverflow.com/questions/60882381/what-is-the-fastest-correct-way-to-detect-that-there-are-no-duplicates-in-a-json
17 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) struct HashedValuerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/HashedValue#<'a>(&'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#);
18
19 impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# for HashedValuerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/HashedValue#<'_> {
20 fn eqrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/impl#[`HashedValue<'_>`][`PartialEq<Self>`]eq().(&self, other: &Selfrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/impl#[`HashedValue<'_>`][`PartialEq<Self>`]) -> bool {
21 cmprust-analyzer cargo jsonschema 0.37.4 ext/cmp/::equalrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal().(self.0rust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/HashedValue#0., other.0rust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/HashedValue#0.)
22 }
23 }
24
25 impl Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# for HashedValuerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/HashedValue#<'_> {}
26
27 impl Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# for HashedValuerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/HashedValue#<'_> {
28 fn hashrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/impl#[`HashedValue<'_>`][Hash]hash().<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
29 match self.0rust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/HashedValue#0. {
30 Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Nullrust-analyzer cargo serde_json 1.0.145 value/Value#Null# => state.write_u32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_u32().(3_221_225_473), // chosen randomly
31 Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Boolrust-analyzer cargo serde_json 1.0.145 value/Value#Bool#(ref item) => item.hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/impls/impl#[bool][Hash]hash().(state),
32 Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Numberrust-analyzer cargo serde_json 1.0.145 value/Value#Number#(ref item) => {
33 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(number) = item.as_f64rust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_f64().() {
34 number.to_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]to_bits().().hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/impls/impl#[u64][Hash]hash().(state);
35 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(number) = item.as_u64rust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_u64().() {
36 number.hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/impls/impl#[u64][Hash]hash().(state);
37 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(number) = item.as_i64rust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_i64().() {
38 number.hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/impls/impl#[i64][Hash]hash().(state);
39 }
40 }
41 Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Stringrust-analyzer cargo serde_json 1.0.145 value/Value#String#(ref item) => item.hashrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Hash]hash().(state),
42 Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Arrayrust-analyzer cargo serde_json 1.0.145 value/Value#Array#(ref items) => {
43 for item in items {
44 HashedValuerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/HashedValue#(item).hashrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/impl#[`HashedValue<'_>`][Hash]hash().(state);
45 }
46 }
47 Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(ref items) => {
48 let mut hash = 0;
49 for (key, value) in items {
50 // We have no way of building a new hasher of type `H`, so we
51 // hardcode using the default hasher of a hash map.
52 let mut item_hasher = AHasherrust-analyzer cargo ahash 0.8.12 fallback_hash/AHasher#::defaultrust-analyzer cargo ahash 0.8.12 impl#[AHasher][Default]default().();
53 key.hashrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Hash]hash().(&mut item_hasher);
54 HashedValuerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/HashedValue#(value).hashrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/impl#[`HashedValue<'_>`][Hash]hash().(&mut item_hasher);
55 hash rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitXorAssign<Self>`]bitxor_assign().^=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitXorAssign<Self>`]bitxor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitXorAssign<Self>`]bitxor_assign().item_hasher.finishrust-analyzer cargo ahash 0.8.12 fallback_hash/impl#[AHasher][Hasher]finish().();
56 }
57 state.write_u64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_u64().(hash);
58 }
59 }
60 }
61 }
62
63 // Empirically calculated threshold after which the validator resorts to hashing.
64 // Calculated for an array of mixed types, large homogeneous arrays of primitive values might be
65 // processed faster with different thresholds, but this one gives a good baseline for the common
66 // case.
67 const ITEMS_SIZE_THRESHOLDrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/ITEMS_SIZE_THRESHOLD.: usize = 15;
68
69 #[inline]
70 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn is_uniquerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/is_unique().(items: &[Valuerust-analyzer cargo serde_json 1.0.145 value/Value#]) -> bool {
71 let size = items.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
72 if size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().1 {
73 // Empty arrays and one-element arrays always contain unique elements
74 true
75 } else if let [first, second] = items {
76 !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().cmprust-analyzer cargo jsonschema 0.37.4 ext/cmp/::equalrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal().(first, second)
77 } else if let [first, second, third] = items {
78 !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().cmprust-analyzer cargo jsonschema 0.37.4 ext/cmp/::equalrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal().(first, second) && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().cmprust-analyzer cargo jsonschema 0.37.4 ext/cmp/::equalrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal().(first, third) && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().cmprust-analyzer cargo jsonschema 0.37.4 ext/cmp/::equalrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal().(second, third)
79 } else if size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().ITEMS_SIZE_THRESHOLDrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/ITEMS_SIZE_THRESHOLD. {
80 // If the array size is small enough we can compare all elements pairwise, which will
81 // be faster than calculating hashes for each element, even if the algorithm is O(N^2)
82 let mut idx = 0_usize;
83 while idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().items.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
84 let mut inner_idx = idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1;
85 while inner_idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().items.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
86 if cmprust-analyzer cargo jsonschema 0.37.4 ext/cmp/::equalrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal().(&items[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &items[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().inner_idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) {
87 return false;
88 }
89 inner_idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
90 }
91 idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
92 }
93 true
94 } else {
95 let mut seen = AHashSetrust-analyzer cargo ahash 0.8.12 hash_set/AHashSet#::with_capacityrust-analyzer cargo ahash 0.8.12 hash_set/impl#[`AHashSet<T>`]with_capacity().(size);
96 items.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(HashedValuerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/HashedValue#).allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(move |x| seen.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(x))
97 }
98 }
99
100 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) struct UniqueItemsValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/UniqueItemsValidator# {
101 locationrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/UniqueItemsValidator#location.: Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#,
102 }
103
104 impl UniqueItemsValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/UniqueItemsValidator# {
105 #[inline]
106 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compilerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/impl#[UniqueItemsValidator]compile().<'a>(location: Locationrust-analyzer cargo jsonschema 0.37.4 paths/Location#) -> CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'a> {
107 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().(UniqueItemsValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/UniqueItemsValidator# { locationrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/UniqueItemsValidator#location. }))
108 }
109 }
110
111 impl Validaterust-analyzer cargo jsonschema 0.37.4 validator/Validate# for UniqueItemsValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/UniqueItemsValidator# {
112 fn is_validrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/impl#[UniqueItemsValidator][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#::Arrayrust-analyzer cargo serde_json 1.0.145 value/Value#Array#(items) = instance {
114 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_uniquerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/is_unique().(items) {
115 return false;
116 }
117 }
118 true
119 }
120
121 fn validaterust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/impl#[UniqueItemsValidator][Validate]validate().<'i>(
122 &self,
123 instance: &'i Valuerust-analyzer cargo serde_json 1.0.145 value/Value#,
124 location: &LazyLocationrust-analyzer cargo jsonschema 0.37.4 paths/LazyLocation#,
125 ctx: &mut ValidationContextrust-analyzer cargo jsonschema 0.37.4 validator/ValidationContext#,
126 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#<'i>> {
127 if self.is_validrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/impl#[UniqueItemsValidator][Validate]is_valid().(instance, ctx) {
128 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
129 } else {
130 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ValidationErrorrust-analyzer cargo jsonschema 0.37.4 error/ValidationError#::unique_itemsrust-analyzer cargo jsonschema 0.37.4 error/impl#[`ValidationError<'a>`]unique_items().(
131 self.locationrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/UniqueItemsValidator#location..clonerust-analyzer cargo jsonschema 0.37.4 paths/impl#[Location][Clone]clone().(),
132 location.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
133 instance,
134 ))
135 }
136 }
137 }
138
139 #[inline]
140 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn compilerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/compile().<'a>(
141 ctx: &compilerrust-analyzer cargo jsonschema 0.37.4 compiler/::Contextrust-analyzer cargo jsonschema 0.37.4 compiler/Context#,
142 _: &'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#>,
143 schema: &'a Valuerust-analyzer cargo serde_json 1.0.145 value/Value#,
144 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<CompilationResultrust-analyzer cargo jsonschema 0.37.4 keywords/CompilationResult#<'a>> {
145 if let Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Boolrust-analyzer cargo serde_json 1.0.145 value/Value#Bool#(value) = schema {
146 if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().value {
147 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().("uniqueItems");
148 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(UniqueItemsValidatorrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/UniqueItemsValidator#::compilerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/impl#[UniqueItemsValidator]compile().(location))
149 } else {
150 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
151 }
152 } else {
153 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
154 }
155 }
156
157 #[cfg(test)]
158 mod testsrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/tests/ {
159 use superrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/::{is_uniquerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/is_unique()., ITEMS_SIZE_THRESHOLDrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/ITEMS_SIZE_THRESHOLD.};
160 use craterust-analyzer cargo jsonschema 0.37.4 crate/::tests_utilrust-analyzer cargo jsonschema 0.37.4 tests_util/;
161 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#};
162 use test_caserust-analyzer cargo test-case 3.3.1 crate/::test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:;
163
164 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
165 fn locationrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/tests/location().() {
166 tests_utilrust-analyzer cargo jsonschema 0.37.4 tests_util/::assert_schema_locationrust-analyzer cargo jsonschema 0.37.4 tests_util/assert_schema_location().(
167 &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"uniqueItems": true}),
168 &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!([1, 1]),
169 "/uniqueItems",
170 );
171 }
172
173 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&[] => true; "empty array")]
174 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&[jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(1)] => true; "one element array")]
175 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&[jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(1), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(2)] => true; "two unique elements")]
176 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&[jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(1), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(1)] => false; "two non-unique elements")]
177 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&[jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(1), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(2), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(3)] => true; "three unique elements")]
178 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&[jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(1), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(2), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(1)] => false; "three non-unique elements")]
179 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&[jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(1), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(2), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(3), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(4), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(5), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(6), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(7), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(8), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(9), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(10), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(11), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(12), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(13), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(14), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(15), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(1.0)] => false; "positive numbers with fractions")]
180 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&[jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().2), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().3), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().4), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().5), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().6), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().7), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().8), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().9), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().10), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().11), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().12), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().13), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().14), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().15), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0)] => false; "negative numbers with fractions")]
181 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&[jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(1), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!("string"), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(true), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(null), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"key": "value"}), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!([1, 2, 3])] => true; "mixed types")]
182 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&[jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"a": 1, "b": 1}), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"a": 1, "b": 2}), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"a": 1, "b": 3})] => true; "complex objects unique")]
183 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&[jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"a": 1, "b": 2}), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"b": 2, "a": 1}), jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"a": 1, "b": 2})] => false; "complex objects non-unique")]
184 fn test_is_uniquerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/tests/test_is_unique().(items: &[Valuerust-analyzer cargo serde_json 1.0.145 value/Value#]) -> bool {
185 is_uniquerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/is_unique().(items)
186 }
187
188 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(ITEMS_SIZE_THRESHOLDrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/ITEMS_SIZE_THRESHOLD. => true; "small array unique")]
189 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(ITEMS_SIZE_THRESHOLDrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/ITEMS_SIZE_THRESHOLD. +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 1 => true; "large array unique")]
190 fn test_unique_arraysrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/tests/test_unique_arrays().(size: usize) -> bool {
191 let arr = (1..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#size).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|i| jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(i)).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
192 is_uniquerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/is_unique().(&arr)
193 }
194
195 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(ITEMS_SIZE_THRESHOLDrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/ITEMS_SIZE_THRESHOLD. => false; "small array non-unique")]
196 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(ITEMS_SIZE_THRESHOLDrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/ITEMS_SIZE_THRESHOLD. +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 1 => false; "large array non-unique")]
197 fn test_non_unique_arraysrust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/tests/test_non_unique_arrays().(size: usize) -> bool {
198 let mut arr = (1..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#size).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|i| jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(i)).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
199 arr[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().size -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(1);
200 is_uniquerust-analyzer cargo jsonschema 0.37.4 keywords/unique_items/is_unique().(&arr)
201 }
202 }