1// Forked from atrium-lexicon
2// https://github.com/atrium-rs/atrium/blob/main/lexicon/atrium-lex/src/lexicon.rs
3// https://github.com/atrium-rs/atrium/blob/main/lexicon/atrium-lex/src/lib.rs
4
5use jacquard_common::{CowStr, into_static::IntoStatic, smol_str::SmolStr, types::blob::MimeType};
6use serde::{Deserialize, Serialize};
7use serde_repr::{Deserialize_repr, Serialize_repr};
8use serde_with::skip_serializing_none;
9use std::collections::BTreeMap;
10
11#[derive(Debug, Serialize_repr, Deserialize_repr, PartialEq, Eq, Clone, Copy)]
12#[repr(u8)]
13pub enum Lexicon {
14 Lexicon1 = 1,
15}
16#[skip_serializing_none]
17#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
18pub struct LexiconDoc<'s> {
19 pub lexicon: Lexicon,
20 #[serde(borrow)]
21 pub id: CowStr<'s>,
22 pub revision: Option<u32>,
23 pub description: Option<CowStr<'s>>,
24 pub defs: BTreeMap<SmolStr, LexUserType<'s>>,
25}
26
27// primitives
28
29#[skip_serializing_none]
30#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
31pub struct LexBoolean<'s> {
32 #[serde(borrow)]
33 pub description: Option<CowStr<'s>>,
34 pub default: Option<bool>,
35 pub r#const: Option<bool>,
36}
37
38/// The Lexicon type `integer`.
39///
40/// Lexicon integers are [specified] as signed and 64-bit, which means that values will
41/// always fit in an `i64`.
42///
43/// [specified]: https://atproto.com/specs/data-model#data-types
44#[skip_serializing_none]
45#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
46pub struct LexInteger<'s> {
47 #[serde(borrow)]
48 pub description: Option<CowStr<'s>>,
49 pub default: Option<i64>,
50 pub minimum: Option<i64>,
51 pub maximum: Option<i64>,
52 pub r#enum: Option<Vec<i64>>,
53 pub r#const: Option<i64>,
54}
55
56#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Copy)]
57#[serde(rename_all = "kebab-case")]
58pub enum LexStringFormat {
59 Datetime,
60 Uri,
61 AtUri,
62 Did,
63 Handle,
64 AtIdentifier,
65 Nsid,
66 Cid,
67 Language,
68 Tid,
69 RecordKey,
70}
71#[skip_serializing_none]
72#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
73#[serde(rename_all = "camelCase")]
74pub struct LexString<'s> {
75 #[serde(borrow)]
76 pub description: Option<CowStr<'s>>,
77 pub format: Option<LexStringFormat>,
78 pub default: Option<CowStr<'s>>,
79 pub min_length: Option<usize>,
80 pub max_length: Option<usize>,
81 pub min_graphemes: Option<usize>,
82 pub max_graphemes: Option<usize>,
83 pub r#enum: Option<Vec<CowStr<'s>>>,
84 pub r#const: Option<CowStr<'s>>,
85 pub known_values: Option<Vec<CowStr<'s>>>,
86}
87
88#[skip_serializing_none]
89#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
90pub struct LexUnknown<'s> {
91 #[serde(borrow)]
92 pub description: Option<CowStr<'s>>,
93}
94// ipld types
95
96#[skip_serializing_none]
97#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
98#[serde(rename_all = "camelCase")]
99pub struct LexBytes<'s> {
100 #[serde(borrow)]
101 pub description: Option<CowStr<'s>>,
102 pub max_length: Option<usize>,
103 pub min_length: Option<usize>,
104}
105
106#[skip_serializing_none]
107#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
108pub struct LexCidLink<'s> {
109 #[serde(borrow)]
110 pub description: Option<CowStr<'s>>,
111}
112
113// references
114
115#[skip_serializing_none]
116#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
117pub struct LexRef<'s> {
118 #[serde(borrow)]
119 pub description: Option<CowStr<'s>>,
120 pub r#ref: CowStr<'s>,
121}
122
123#[skip_serializing_none]
124#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
125pub struct LexRefUnion<'s> {
126 #[serde(borrow)]
127 pub description: Option<CowStr<'s>>,
128 pub refs: Vec<CowStr<'s>>,
129 pub closed: Option<bool>,
130}
131
132// blobs
133
134#[skip_serializing_none]
135#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
136#[serde(rename_all = "camelCase")]
137pub struct LexBlob<'s> {
138 #[serde(borrow)]
139 pub description: Option<CowStr<'s>>,
140 pub accept: Option<Vec<MimeType<'s>>>,
141 pub max_size: Option<usize>,
142}
143
144// complex types
145
146#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
147#[serde(tag = "type", rename_all = "kebab-case")]
148pub enum LexArrayItem<'s> {
149 // lexPrimitive
150 Boolean(LexBoolean<'s>),
151 Integer(LexInteger<'s>),
152 String(LexString<'s>),
153 Unknown(LexUnknown<'s>),
154 // lexIpldType
155 Bytes(LexBytes<'s>),
156 CidLink(LexCidLink<'s>),
157 // lexBlob
158 #[serde(borrow)]
159 Blob(LexBlob<'s>),
160 // lexRefVariant
161 Ref(LexRef<'s>),
162 Union(LexRefUnion<'s>),
163}
164#[skip_serializing_none]
165#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
166#[serde(rename_all = "camelCase")]
167pub struct LexArray<'s> {
168 #[serde(borrow)]
169 pub description: Option<CowStr<'s>>,
170 pub items: LexArrayItem<'s>,
171 pub min_length: Option<usize>,
172 pub max_length: Option<usize>,
173}
174
175#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
176#[serde(tag = "type", rename_all = "lowercase")]
177pub enum LexPrimitiveArrayItem<'s> {
178 // lexPrimitive
179 #[serde(borrow)]
180 Boolean(LexBoolean<'s>),
181 Integer(LexInteger<'s>),
182 String(LexString<'s>),
183 Unknown(LexUnknown<'s>),
184}
185#[skip_serializing_none]
186#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
187#[serde(rename_all = "camelCase")]
188pub struct LexPrimitiveArray<'s> {
189 #[serde(borrow)]
190 pub description: Option<CowStr<'s>>,
191 pub items: LexPrimitiveArrayItem<'s>,
192 pub min_length: Option<usize>,
193 pub max_length: Option<usize>,
194}
195
196#[skip_serializing_none]
197#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
198pub struct LexToken<'s> {
199 #[serde(borrow)]
200 pub description: Option<CowStr<'s>>,
201}
202
203#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
204#[serde(tag = "type", rename_all = "kebab-case")]
205pub enum LexObjectProperty<'s> {
206 // lexRefVariant
207 #[serde(borrow)]
208 Ref(LexRef<'s>),
209 Union(LexRefUnion<'s>),
210 // lexIpldType
211 Bytes(LexBytes<'s>),
212 CidLink(LexCidLink<'s>),
213 // lexArray
214 Array(LexArray<'s>),
215 // lexBlob
216 Blob(LexBlob<'s>),
217 // lexPrimitive
218 Boolean(LexBoolean<'s>),
219 Integer(LexInteger<'s>),
220 String(LexString<'s>),
221 Unknown(LexUnknown<'s>),
222}
223#[skip_serializing_none]
224#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
225pub struct LexObject<'s> {
226 #[serde(borrow)]
227 pub description: Option<CowStr<'s>>,
228 pub required: Option<Vec<SmolStr>>,
229 pub nullable: Option<Vec<SmolStr>>,
230 pub properties: BTreeMap<SmolStr, LexObjectProperty<'s>>,
231}
232
233// xrpc
234
235#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
236#[serde(tag = "type", rename_all = "lowercase")]
237pub enum LexXrpcParametersProperty<'s> {
238 // lexPrimitive
239 #[serde(borrow)]
240 Boolean(LexBoolean<'s>),
241 Integer(LexInteger<'s>),
242 String(LexString<'s>),
243 Unknown(LexUnknown<'s>),
244 // lexPrimitiveArray
245 Array(LexPrimitiveArray<'s>),
246}
247#[skip_serializing_none]
248#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
249pub struct LexXrpcParameters<'s> {
250 #[serde(borrow)]
251 pub description: Option<CowStr<'s>>,
252 pub required: Option<Vec<SmolStr>>,
253 pub properties: BTreeMap<SmolStr, LexXrpcParametersProperty<'s>>,
254}
255
256#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
257#[serde(tag = "type", rename_all = "lowercase")]
258pub enum LexXrpcBodySchema<'s> {
259 // lexRefVariant
260 #[serde(borrow)]
261 Ref(LexRef<'s>),
262 Union(LexRefUnion<'s>),
263 // lexObject
264 Object(LexObject<'s>),
265}
266#[skip_serializing_none]
267#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
268pub struct LexXrpcBody<'s> {
269 #[serde(borrow)]
270 pub description: Option<CowStr<'s>>,
271 pub encoding: CowStr<'s>,
272 pub schema: Option<LexXrpcBodySchema<'s>>,
273}
274
275#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
276#[serde(tag = "type", rename_all = "lowercase")]
277pub enum LexXrpcSubscriptionMessageSchema<'s> {
278 // lexRefVariant
279 #[serde(borrow)]
280 Ref(LexRef<'s>),
281 Union(LexRefUnion<'s>),
282 // lexObject
283 Object(LexObject<'s>),
284}
285#[skip_serializing_none]
286#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
287pub struct LexXrpcSubscriptionMessage<'s> {
288 #[serde(borrow)]
289 pub description: Option<CowStr<'s>>,
290 pub schema: Option<LexXrpcSubscriptionMessageSchema<'s>>,
291}
292
293#[skip_serializing_none]
294#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
295pub struct LexXrpcError<'s> {
296 #[serde(borrow)]
297 pub description: Option<CowStr<'s>>,
298 pub name: CowStr<'s>,
299}
300
301#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
302#[serde(tag = "type", rename_all = "lowercase")]
303pub enum LexXrpcQueryParameter<'s> {
304 #[serde(borrow)]
305 Params(LexXrpcParameters<'s>),
306}
307#[skip_serializing_none]
308#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
309pub struct LexXrpcQuery<'s> {
310 #[serde(borrow)]
311 pub description: Option<CowStr<'s>>,
312 pub parameters: Option<LexXrpcQueryParameter<'s>>,
313 pub output: Option<LexXrpcBody<'s>>,
314 pub errors: Option<Vec<LexXrpcError<'s>>>,
315}
316
317#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
318#[serde(tag = "type", rename_all = "lowercase")]
319pub enum LexXrpcProcedureParameter<'s> {
320 #[serde(borrow)]
321 Params(LexXrpcParameters<'s>),
322}
323#[skip_serializing_none]
324#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
325pub struct LexXrpcProcedure<'s> {
326 #[serde(borrow)]
327 pub description: Option<CowStr<'s>>,
328 pub parameters: Option<LexXrpcProcedureParameter<'s>>,
329 pub input: Option<LexXrpcBody<'s>>,
330 pub output: Option<LexXrpcBody<'s>>,
331 pub errors: Option<Vec<LexXrpcError<'s>>>,
332}
333
334#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
335#[serde(tag = "type", rename_all = "lowercase")]
336pub enum LexXrpcSubscriptionParameter<'s> {
337 #[serde(borrow)]
338 Params(LexXrpcParameters<'s>),
339}
340#[skip_serializing_none]
341#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
342pub struct LexXrpcSubscription<'s> {
343 #[serde(borrow)]
344 pub description: Option<CowStr<'s>>,
345 pub parameters: Option<LexXrpcSubscriptionParameter<'s>>,
346 pub message: Option<LexXrpcSubscriptionMessage<'s>>,
347 pub infos: Option<Vec<LexXrpcError<'s>>>,
348 pub errors: Option<Vec<LexXrpcError<'s>>>,
349}
350
351// database
352
353#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
354#[serde(tag = "type", rename_all = "lowercase")]
355pub enum LexRecordRecord<'s> {
356 #[serde(borrow)]
357 Object(LexObject<'s>),
358}
359#[skip_serializing_none]
360#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
361pub struct LexRecord<'s> {
362 #[serde(borrow)]
363 pub description: Option<CowStr<'s>>,
364 pub key: Option<CowStr<'s>>,
365 pub record: LexRecordRecord<'s>,
366}
367
368// core
369
370#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
371#[serde(tag = "type", rename_all = "kebab-case")]
372pub enum LexUserType<'s> {
373 // lexRecord
374 #[serde(borrow)]
375 Record(LexRecord<'s>),
376 // lexXrpcQuery
377 #[serde(rename = "query")]
378 XrpcQuery(LexXrpcQuery<'s>),
379 // lexXrpcProcedure
380 #[serde(rename = "procedure")]
381 XrpcProcedure(LexXrpcProcedure<'s>),
382 // lexXrpcSubscription
383 #[serde(rename = "subscription")]
384 XrpcSubscription(LexXrpcSubscription<'s>),
385 // lexBlob
386 Blob(LexBlob<'s>),
387 // lexArray
388 Array(LexArray<'s>),
389 // lexToken
390 Token(LexToken<'s>),
391 // lexObject
392 Object(LexObject<'s>),
393 // lexBoolean,
394 Boolean(LexBoolean<'s>),
395 // lexInteger,
396 Integer(LexInteger<'s>),
397 // lexString,
398 String(LexString<'s>),
399 // lexBytes
400 Bytes(LexBytes<'s>),
401 // lexCidLink
402 CidLink(LexCidLink<'s>),
403 // lexUnknown
404 Unknown(LexUnknown<'s>),
405}
406
407// IntoStatic implementations for all lexicon types
408// These enable converting borrowed lexicon docs to owned 'static versions
409
410#[allow(unused)]
411macro_rules! impl_into_static_for_lex_struct {
412 ($($ty:ident),+ $(,)?) => {
413 $(
414 impl IntoStatic for $ty<'_> {
415 type Output = $ty<'static>;
416
417 fn into_static(self) -> Self::Output {
418 let Self {
419 $(description,)?
420 ..$fields
421 } = self;
422 Self::Output {
423 $(description: description.into_static(),)?
424 ..$fields.into_static()
425 }
426 }
427 }
428 )+
429 };
430}
431
432// Simpler approach: just clone and convert each field
433impl IntoStatic for Lexicon {
434 type Output = Lexicon;
435 fn into_static(self) -> Self::Output {
436 self
437 }
438}
439
440impl IntoStatic for LexStringFormat {
441 type Output = LexStringFormat;
442 fn into_static(self) -> Self::Output {
443 self
444 }
445}
446
447impl IntoStatic for LexiconDoc<'_> {
448 type Output = LexiconDoc<'static>;
449 fn into_static(self) -> Self::Output {
450 LexiconDoc {
451 lexicon: self.lexicon,
452 id: self.id.into_static(),
453 revision: self.revision,
454 description: self.description.into_static(),
455 defs: self.defs.into_static(),
456 }
457 }
458}
459
460impl IntoStatic for LexBoolean<'_> {
461 type Output = LexBoolean<'static>;
462 fn into_static(self) -> Self::Output {
463 LexBoolean {
464 description: self.description.into_static(),
465 default: self.default,
466 r#const: self.r#const,
467 }
468 }
469}
470
471impl IntoStatic for LexInteger<'_> {
472 type Output = LexInteger<'static>;
473 fn into_static(self) -> Self::Output {
474 LexInteger {
475 description: self.description.into_static(),
476 default: self.default,
477 minimum: self.minimum,
478 maximum: self.maximum,
479 r#enum: self.r#enum,
480 r#const: self.r#const,
481 }
482 }
483}
484
485impl IntoStatic for LexString<'_> {
486 type Output = LexString<'static>;
487 fn into_static(self) -> Self::Output {
488 LexString {
489 description: self.description.into_static(),
490 format: self.format,
491 default: self.default.into_static(),
492 min_length: self.min_length,
493 max_length: self.max_length,
494 min_graphemes: self.min_graphemes,
495 max_graphemes: self.max_graphemes,
496 r#enum: self.r#enum.into_static(),
497 r#const: self.r#const.into_static(),
498 known_values: self.known_values.into_static(),
499 }
500 }
501}
502
503impl IntoStatic for LexUnknown<'_> {
504 type Output = LexUnknown<'static>;
505 fn into_static(self) -> Self::Output {
506 LexUnknown {
507 description: self.description.into_static(),
508 }
509 }
510}
511
512impl IntoStatic for LexBytes<'_> {
513 type Output = LexBytes<'static>;
514 fn into_static(self) -> Self::Output {
515 LexBytes {
516 description: self.description.into_static(),
517 max_length: self.max_length,
518 min_length: self.min_length,
519 }
520 }
521}
522
523impl IntoStatic for LexCidLink<'_> {
524 type Output = LexCidLink<'static>;
525 fn into_static(self) -> Self::Output {
526 LexCidLink {
527 description: self.description.into_static(),
528 }
529 }
530}
531
532impl IntoStatic for LexRef<'_> {
533 type Output = LexRef<'static>;
534 fn into_static(self) -> Self::Output {
535 LexRef {
536 description: self.description.into_static(),
537 r#ref: self.r#ref.into_static(),
538 }
539 }
540}
541
542impl IntoStatic for LexRefUnion<'_> {
543 type Output = LexRefUnion<'static>;
544 fn into_static(self) -> Self::Output {
545 LexRefUnion {
546 description: self.description.into_static(),
547 refs: self.refs.into_static(),
548 closed: self.closed,
549 }
550 }
551}
552
553impl IntoStatic for LexBlob<'_> {
554 type Output = LexBlob<'static>;
555 fn into_static(self) -> Self::Output {
556 LexBlob {
557 description: self.description.into_static(),
558 accept: self.accept.into_static(),
559 max_size: self.max_size,
560 }
561 }
562}
563
564impl IntoStatic for LexArrayItem<'_> {
565 type Output = LexArrayItem<'static>;
566 fn into_static(self) -> Self::Output {
567 match self {
568 Self::Boolean(x) => LexArrayItem::Boolean(x.into_static()),
569 Self::Integer(x) => LexArrayItem::Integer(x.into_static()),
570 Self::String(x) => LexArrayItem::String(x.into_static()),
571 Self::Unknown(x) => LexArrayItem::Unknown(x.into_static()),
572 Self::Bytes(x) => LexArrayItem::Bytes(x.into_static()),
573 Self::CidLink(x) => LexArrayItem::CidLink(x.into_static()),
574 Self::Blob(x) => LexArrayItem::Blob(x.into_static()),
575 Self::Ref(x) => LexArrayItem::Ref(x.into_static()),
576 Self::Union(x) => LexArrayItem::Union(x.into_static()),
577 }
578 }
579}
580
581impl IntoStatic for LexArray<'_> {
582 type Output = LexArray<'static>;
583 fn into_static(self) -> Self::Output {
584 LexArray {
585 description: self.description.into_static(),
586 items: self.items.into_static(),
587 min_length: self.min_length,
588 max_length: self.max_length,
589 }
590 }
591}
592
593impl IntoStatic for LexPrimitiveArrayItem<'_> {
594 type Output = LexPrimitiveArrayItem<'static>;
595 fn into_static(self) -> Self::Output {
596 match self {
597 Self::Boolean(x) => LexPrimitiveArrayItem::Boolean(x.into_static()),
598 Self::Integer(x) => LexPrimitiveArrayItem::Integer(x.into_static()),
599 Self::String(x) => LexPrimitiveArrayItem::String(x.into_static()),
600 Self::Unknown(x) => LexPrimitiveArrayItem::Unknown(x.into_static()),
601 }
602 }
603}
604
605impl IntoStatic for LexPrimitiveArray<'_> {
606 type Output = LexPrimitiveArray<'static>;
607 fn into_static(self) -> Self::Output {
608 LexPrimitiveArray {
609 description: self.description.into_static(),
610 items: self.items.into_static(),
611 min_length: self.min_length,
612 max_length: self.max_length,
613 }
614 }
615}
616
617impl IntoStatic for LexToken<'_> {
618 type Output = LexToken<'static>;
619 fn into_static(self) -> Self::Output {
620 LexToken {
621 description: self.description.into_static(),
622 }
623 }
624}
625
626impl IntoStatic for LexObjectProperty<'_> {
627 type Output = LexObjectProperty<'static>;
628 fn into_static(self) -> Self::Output {
629 match self {
630 Self::Ref(x) => LexObjectProperty::Ref(x.into_static()),
631 Self::Union(x) => LexObjectProperty::Union(x.into_static()),
632 Self::Bytes(x) => LexObjectProperty::Bytes(x.into_static()),
633 Self::CidLink(x) => LexObjectProperty::CidLink(x.into_static()),
634 Self::Array(x) => LexObjectProperty::Array(x.into_static()),
635 Self::Blob(x) => LexObjectProperty::Blob(x.into_static()),
636 Self::Boolean(x) => LexObjectProperty::Boolean(x.into_static()),
637 Self::Integer(x) => LexObjectProperty::Integer(x.into_static()),
638 Self::String(x) => LexObjectProperty::String(x.into_static()),
639 Self::Unknown(x) => LexObjectProperty::Unknown(x.into_static()),
640 }
641 }
642}
643
644impl IntoStatic for LexObject<'_> {
645 type Output = LexObject<'static>;
646 fn into_static(self) -> Self::Output {
647 LexObject {
648 description: self.description.into_static(),
649 required: self.required,
650 nullable: self.nullable,
651 properties: self.properties.into_static(),
652 }
653 }
654}
655
656impl IntoStatic for LexXrpcParametersProperty<'_> {
657 type Output = LexXrpcParametersProperty<'static>;
658 fn into_static(self) -> Self::Output {
659 match self {
660 Self::Boolean(x) => LexXrpcParametersProperty::Boolean(x.into_static()),
661 Self::Integer(x) => LexXrpcParametersProperty::Integer(x.into_static()),
662 Self::String(x) => LexXrpcParametersProperty::String(x.into_static()),
663 Self::Unknown(x) => LexXrpcParametersProperty::Unknown(x.into_static()),
664 Self::Array(x) => LexXrpcParametersProperty::Array(x.into_static()),
665 }
666 }
667}
668
669impl IntoStatic for LexXrpcParameters<'_> {
670 type Output = LexXrpcParameters<'static>;
671 fn into_static(self) -> Self::Output {
672 LexXrpcParameters {
673 description: self.description.into_static(),
674 required: self.required,
675 properties: self.properties.into_static(),
676 }
677 }
678}
679
680impl IntoStatic for LexXrpcBodySchema<'_> {
681 type Output = LexXrpcBodySchema<'static>;
682 fn into_static(self) -> Self::Output {
683 match self {
684 Self::Ref(x) => LexXrpcBodySchema::Ref(x.into_static()),
685 Self::Union(x) => LexXrpcBodySchema::Union(x.into_static()),
686 Self::Object(x) => LexXrpcBodySchema::Object(x.into_static()),
687 }
688 }
689}
690
691impl IntoStatic for LexXrpcBody<'_> {
692 type Output = LexXrpcBody<'static>;
693 fn into_static(self) -> Self::Output {
694 LexXrpcBody {
695 description: self.description.into_static(),
696 encoding: self.encoding.into_static(),
697 schema: self.schema.into_static(),
698 }
699 }
700}
701
702impl IntoStatic for LexXrpcSubscriptionMessageSchema<'_> {
703 type Output = LexXrpcSubscriptionMessageSchema<'static>;
704 fn into_static(self) -> Self::Output {
705 match self {
706 Self::Ref(x) => LexXrpcSubscriptionMessageSchema::Ref(x.into_static()),
707 Self::Union(x) => LexXrpcSubscriptionMessageSchema::Union(x.into_static()),
708 Self::Object(x) => LexXrpcSubscriptionMessageSchema::Object(x.into_static()),
709 }
710 }
711}
712
713impl IntoStatic for LexXrpcSubscriptionMessage<'_> {
714 type Output = LexXrpcSubscriptionMessage<'static>;
715 fn into_static(self) -> Self::Output {
716 LexXrpcSubscriptionMessage {
717 description: self.description.into_static(),
718 schema: self.schema.into_static(),
719 }
720 }
721}
722
723impl IntoStatic for LexXrpcError<'_> {
724 type Output = LexXrpcError<'static>;
725 fn into_static(self) -> Self::Output {
726 LexXrpcError {
727 description: self.description.into_static(),
728 name: self.name.into_static(),
729 }
730 }
731}
732
733impl IntoStatic for LexXrpcQueryParameter<'_> {
734 type Output = LexXrpcQueryParameter<'static>;
735 fn into_static(self) -> Self::Output {
736 match self {
737 Self::Params(x) => LexXrpcQueryParameter::Params(x.into_static()),
738 }
739 }
740}
741
742impl IntoStatic for LexXrpcQuery<'_> {
743 type Output = LexXrpcQuery<'static>;
744 fn into_static(self) -> Self::Output {
745 LexXrpcQuery {
746 description: self.description.into_static(),
747 parameters: self.parameters.into_static(),
748 output: self.output.into_static(),
749 errors: self.errors.into_static(),
750 }
751 }
752}
753
754impl IntoStatic for LexXrpcProcedureParameter<'_> {
755 type Output = LexXrpcProcedureParameter<'static>;
756 fn into_static(self) -> Self::Output {
757 match self {
758 Self::Params(x) => LexXrpcProcedureParameter::Params(x.into_static()),
759 }
760 }
761}
762
763impl IntoStatic for LexXrpcProcedure<'_> {
764 type Output = LexXrpcProcedure<'static>;
765 fn into_static(self) -> Self::Output {
766 LexXrpcProcedure {
767 description: self.description.into_static(),
768 parameters: self.parameters.into_static(),
769 input: self.input.into_static(),
770 output: self.output.into_static(),
771 errors: self.errors.into_static(),
772 }
773 }
774}
775
776impl IntoStatic for LexXrpcSubscriptionParameter<'_> {
777 type Output = LexXrpcSubscriptionParameter<'static>;
778 fn into_static(self) -> Self::Output {
779 match self {
780 Self::Params(x) => LexXrpcSubscriptionParameter::Params(x.into_static()),
781 }
782 }
783}
784
785impl IntoStatic for LexXrpcSubscription<'_> {
786 type Output = LexXrpcSubscription<'static>;
787 fn into_static(self) -> Self::Output {
788 LexXrpcSubscription {
789 description: self.description.into_static(),
790 parameters: self.parameters.into_static(),
791 message: self.message.into_static(),
792 infos: self.infos.into_static(),
793 errors: self.errors.into_static(),
794 }
795 }
796}
797
798impl IntoStatic for LexRecordRecord<'_> {
799 type Output = LexRecordRecord<'static>;
800 fn into_static(self) -> Self::Output {
801 match self {
802 Self::Object(x) => LexRecordRecord::Object(x.into_static()),
803 }
804 }
805}
806
807impl IntoStatic for LexRecord<'_> {
808 type Output = LexRecord<'static>;
809 fn into_static(self) -> Self::Output {
810 LexRecord {
811 description: self.description.into_static(),
812 key: self.key.into_static(),
813 record: self.record.into_static(),
814 }
815 }
816}
817
818impl IntoStatic for LexUserType<'_> {
819 type Output = LexUserType<'static>;
820 fn into_static(self) -> Self::Output {
821 match self {
822 Self::Record(x) => LexUserType::Record(x.into_static()),
823 Self::XrpcQuery(x) => LexUserType::XrpcQuery(x.into_static()),
824 Self::XrpcProcedure(x) => LexUserType::XrpcProcedure(x.into_static()),
825 Self::XrpcSubscription(x) => LexUserType::XrpcSubscription(x.into_static()),
826 Self::Blob(x) => LexUserType::Blob(x.into_static()),
827 Self::Array(x) => LexUserType::Array(x.into_static()),
828 Self::Token(x) => LexUserType::Token(x.into_static()),
829 Self::Object(x) => LexUserType::Object(x.into_static()),
830 Self::Boolean(x) => LexUserType::Boolean(x.into_static()),
831 Self::Integer(x) => LexUserType::Integer(x.into_static()),
832 Self::String(x) => LexUserType::String(x.into_static()),
833 Self::Bytes(x) => LexUserType::Bytes(x.into_static()),
834 Self::CidLink(x) => LexUserType::CidLink(x.into_static()),
835 Self::Unknown(x) => LexUserType::Unknown(x.into_static()),
836 }
837 }
838}
839
840#[cfg(test)]
841mod tests {
842 use super::*;
843
844 const LEXICON_EXAMPLE_TOKEN: &str = r#"
845{
846 "lexicon": 1,
847 "id": "com.socialapp.actorUser",
848 "defs": {
849 "main": {
850 "type": "token",
851 "description": "Actor type of 'User'"
852 }
853 }
854}"#;
855
856 #[test]
857 fn parse() {
858 let doc = serde_json::from_str::<LexiconDoc>(LEXICON_EXAMPLE_TOKEN)
859 .expect("failed to deserialize");
860 assert_eq!(doc.lexicon, Lexicon::Lexicon1);
861 assert_eq!(doc.id, "com.socialapp.actorUser");
862 assert_eq!(doc.revision, None);
863 assert_eq!(doc.description, None);
864 assert_eq!(doc.defs.len(), 1);
865 }
866}