1use super::{Collection, Field, Index, Kind};
2
3impl Kind {
5 #[must_use]
10 pub fn any() -> Self {
11 Self {
12 bytes: Some(()),
13 integer: Some(()),
14 float: Some(()),
15 boolean: Some(()),
16 timestamp: Some(()),
17 regex: Some(()),
18 null: Some(()),
19 undefined: Some(()),
20 array: Some(Collection::any()),
21 object: Some(Collection::any()),
22 }
23 }
24
25 #[must_use]
30 pub fn json() -> Self {
31 Self {
32 bytes: Some(()),
33 integer: Some(()),
34 float: Some(()),
35 boolean: Some(()),
36 timestamp: None,
37 regex: None,
38 null: Some(()),
39 undefined: None,
40 array: Some(Collection::json()),
41 object: Some(Collection::json()),
42 }
43 }
44
45 #[must_use]
47 pub const fn bytes() -> Self {
48 Self {
49 bytes: Some(()),
50 integer: None,
51 float: None,
52 boolean: None,
53 timestamp: None,
54 regex: None,
55 null: None,
56 undefined: None,
57 array: None,
58 object: None,
59 }
60 }
61
62 #[must_use]
64 pub const fn integer() -> Self {
65 Self {
66 bytes: None,
67 integer: Some(()),
68 float: None,
69 boolean: None,
70 timestamp: None,
71 regex: None,
72 null: None,
73 undefined: None,
74 array: None,
75 object: None,
76 }
77 }
78
79 #[must_use]
81 pub const fn float() -> Self {
82 Self {
83 bytes: None,
84 integer: None,
85 float: Some(()),
86 boolean: None,
87 timestamp: None,
88 regex: None,
89 null: None,
90 undefined: None,
91 array: None,
92 object: None,
93 }
94 }
95
96 #[must_use]
98 pub const fn boolean() -> Self {
99 Self {
100 bytes: None,
101 integer: None,
102 float: None,
103 boolean: Some(()),
104 timestamp: None,
105 regex: None,
106 null: None,
107 undefined: None,
108 array: None,
109 object: None,
110 }
111 }
112
113 #[must_use]
115 pub const fn timestamp() -> Self {
116 Self {
117 bytes: None,
118 integer: None,
119 float: None,
120 boolean: None,
121 timestamp: Some(()),
122 regex: None,
123 null: None,
124 undefined: None,
125 array: None,
126 object: None,
127 }
128 }
129
130 #[must_use]
132 pub const fn regex() -> Self {
133 Self {
134 bytes: None,
135 integer: None,
136 float: None,
137 boolean: None,
138 timestamp: None,
139 regex: Some(()),
140 null: None,
141 undefined: None,
142 array: None,
143 object: None,
144 }
145 }
146
147 #[must_use]
149 pub const fn null() -> Self {
150 Self {
151 bytes: None,
152 integer: None,
153 float: None,
154 boolean: None,
155 timestamp: None,
156 regex: None,
157 null: Some(()),
158 undefined: None,
159 array: None,
160 object: None,
161 }
162 }
163
164 #[must_use]
166 pub const fn undefined() -> Self {
167 Self {
168 bytes: None,
169 integer: None,
170 float: None,
171 boolean: None,
172 timestamp: None,
173 regex: None,
174 null: None,
175 undefined: Some(()),
176 array: None,
177 object: None,
178 }
179 }
180
181 #[must_use]
183 pub const fn never() -> Self {
184 Self {
185 bytes: None,
186 integer: None,
187 float: None,
188 boolean: None,
189 timestamp: None,
190 regex: None,
191 null: None,
192 undefined: None,
193 array: None,
194 object: None,
195 }
196 }
197
198 #[must_use]
200 pub fn array(collection: impl Into<Collection<Index>>) -> Self {
201 Self {
202 bytes: None,
203 integer: None,
204 float: None,
205 boolean: None,
206 timestamp: None,
207 regex: None,
208 null: None,
209 undefined: None,
210 array: Some(collection.into()),
211 object: None,
212 }
213 }
214
215 #[must_use]
217 pub fn object(collection: impl Into<Collection<Field>>) -> Self {
218 Self {
219 bytes: None,
220 integer: None,
221 float: None,
222 boolean: None,
223 timestamp: None,
224 regex: None,
225 null: None,
226 undefined: None,
227 array: None,
228 object: Some(collection.into()),
229 }
230 }
231
232 #[must_use]
234 pub fn any_object() -> Self {
235 Self::object(Collection::any())
236 }
237}
238
239impl Kind {
241 #[must_use]
243 pub const fn or_bytes(mut self) -> Self {
244 self.bytes = Some(());
245 self
246 }
247
248 #[must_use]
250 pub const fn or_integer(mut self) -> Self {
251 self.integer = Some(());
252 self
253 }
254
255 #[must_use]
257 pub const fn or_float(mut self) -> Self {
258 self.float = Some(());
259 self
260 }
261
262 #[must_use]
264 pub const fn or_boolean(mut self) -> Self {
265 self.boolean = Some(());
266 self
267 }
268
269 #[must_use]
271 pub const fn or_timestamp(mut self) -> Self {
272 self.timestamp = Some(());
273 self
274 }
275
276 #[must_use]
278 pub const fn or_regex(mut self) -> Self {
279 self.regex = Some(());
280 self
281 }
282
283 #[must_use]
285 pub const fn or_null(mut self) -> Self {
286 self.null = Some(());
287 self
288 }
289
290 #[must_use]
292 pub const fn or_undefined(mut self) -> Self {
293 self.undefined = Some(());
294 self
295 }
296
297 #[must_use]
299 pub fn or_array(mut self, collection: impl Into<Collection<Index>>) -> Self {
300 self.array = Some(collection.into());
301 self
302 }
303
304 #[must_use]
306 pub fn or_object(mut self, collection: impl Into<Collection<Field>>) -> Self {
307 self.object = Some(collection.into());
308 self
309 }
310}
311
312impl Kind {
314 pub fn add_bytes(&mut self) -> bool {
318 self.bytes.replace(()).is_none()
319 }
320
321 pub fn add_integer(&mut self) -> bool {
325 self.integer.replace(()).is_none()
326 }
327
328 pub fn add_float(&mut self) -> bool {
332 self.float.replace(()).is_none()
333 }
334
335 pub fn add_boolean(&mut self) -> bool {
339 self.boolean.replace(()).is_none()
340 }
341
342 pub fn add_timestamp(&mut self) -> bool {
346 self.timestamp.replace(()).is_none()
347 }
348
349 pub fn add_regex(&mut self) -> bool {
353 self.regex.replace(()).is_none()
354 }
355
356 pub fn add_null(&mut self) -> bool {
360 self.null.replace(()).is_none()
361 }
362
363 pub fn add_undefined(&mut self) -> bool {
367 self.undefined.replace(()).is_none()
368 }
369
370 pub fn add_array(&mut self, collection: impl Into<Collection<Index>>) -> bool {
374 self.array.replace(collection.into()).is_none()
375 }
376
377 pub fn add_object(&mut self, collection: impl Into<Collection<Field>>) -> bool {
381 self.object.replace(collection.into()).is_none()
382 }
383}
384
385impl Kind {
387 pub fn remove_bytes(&mut self) -> bool {
391 self.bytes.take().is_some()
392 }
393
394 pub fn remove_integer(&mut self) -> bool {
398 self.integer.take().is_some()
399 }
400
401 pub fn remove_float(&mut self) -> bool {
405 self.float.take().is_some()
406 }
407
408 pub fn remove_boolean(&mut self) -> bool {
412 self.boolean.take().is_some()
413 }
414
415 pub fn remove_timestamp(&mut self) -> bool {
419 self.timestamp.take().is_some()
420 }
421
422 pub fn remove_regex(&mut self) -> bool {
426 self.regex.take().is_some()
427 }
428
429 pub fn remove_null(&mut self) -> bool {
433 self.null.take().is_some()
434 }
435
436 pub fn remove_undefined(&mut self) -> bool {
440 self.undefined.take().is_some()
441 }
442
443 pub fn remove_array(&mut self) -> bool {
447 self.array.take().is_some()
448 }
449
450 pub fn remove_object(&mut self) -> bool {
454 self.object.take().is_some()
455 }
456}
457
458impl Kind {
460 #[must_use]
462 pub fn without_undefined(&self) -> Self {
463 let mut kind = self.clone();
464 kind.remove_undefined();
465 kind
466 }
467
468 #[must_use]
470 pub fn without_array(&self) -> Self {
471 let mut kind = self.clone();
472 kind.remove_array();
473 kind
474 }
475
476 #[must_use]
478 pub fn without_object(&self) -> Self {
479 let mut kind = self.clone();
480 kind.remove_object();
481 kind
482 }
483}