A better Rust ATProto crate
at lifetimes 27 kB view raw
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 // lexObject 161 Object(LexObject<'s>), 162 // lexRefVariant 163 Ref(LexRef<'s>), 164 Union(LexRefUnion<'s>), 165} 166#[skip_serializing_none] 167#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 168#[serde(rename_all = "camelCase")] 169pub struct LexArray<'s> { 170 #[serde(borrow)] 171 pub description: Option<CowStr<'s>>, 172 pub items: LexArrayItem<'s>, 173 pub min_length: Option<usize>, 174 pub max_length: Option<usize>, 175} 176 177#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 178#[serde(tag = "type", rename_all = "lowercase")] 179pub enum LexPrimitiveArrayItem<'s> { 180 // lexPrimitive 181 #[serde(borrow)] 182 Boolean(LexBoolean<'s>), 183 Integer(LexInteger<'s>), 184 String(LexString<'s>), 185 Unknown(LexUnknown<'s>), 186} 187#[skip_serializing_none] 188#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 189#[serde(rename_all = "camelCase")] 190pub struct LexPrimitiveArray<'s> { 191 #[serde(borrow)] 192 pub description: Option<CowStr<'s>>, 193 pub items: LexPrimitiveArrayItem<'s>, 194 pub min_length: Option<usize>, 195 pub max_length: Option<usize>, 196} 197 198#[skip_serializing_none] 199#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 200pub struct LexToken<'s> { 201 #[serde(borrow)] 202 pub description: Option<CowStr<'s>>, 203} 204 205#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 206#[serde(tag = "type", rename_all = "kebab-case")] 207pub enum LexObjectProperty<'s> { 208 // lexRefVariant 209 #[serde(borrow)] 210 Ref(LexRef<'s>), 211 Union(LexRefUnion<'s>), 212 // lexIpldType 213 Bytes(LexBytes<'s>), 214 CidLink(LexCidLink<'s>), 215 // lexArray 216 Array(LexArray<'s>), 217 // lexBlob 218 Blob(LexBlob<'s>), 219 // lexObject (nested) 220 Object(LexObject<'s>), 221 // lexPrimitive 222 Boolean(LexBoolean<'s>), 223 Integer(LexInteger<'s>), 224 String(LexString<'s>), 225 Unknown(LexUnknown<'s>), 226} 227#[skip_serializing_none] 228#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 229pub struct LexObject<'s> { 230 #[serde(borrow)] 231 pub description: Option<CowStr<'s>>, 232 pub required: Option<Vec<SmolStr>>, 233 pub nullable: Option<Vec<SmolStr>>, 234 pub properties: BTreeMap<SmolStr, LexObjectProperty<'s>>, 235} 236 237// xrpc 238 239#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 240#[serde(tag = "type", rename_all = "lowercase")] 241pub enum LexXrpcParametersProperty<'s> { 242 // lexPrimitive 243 #[serde(borrow)] 244 Boolean(LexBoolean<'s>), 245 Integer(LexInteger<'s>), 246 String(LexString<'s>), 247 Unknown(LexUnknown<'s>), 248 // lexPrimitiveArray 249 Array(LexPrimitiveArray<'s>), 250} 251#[skip_serializing_none] 252#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 253pub struct LexXrpcParameters<'s> { 254 #[serde(borrow)] 255 pub description: Option<CowStr<'s>>, 256 pub required: Option<Vec<SmolStr>>, 257 pub properties: BTreeMap<SmolStr, LexXrpcParametersProperty<'s>>, 258} 259 260#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 261#[serde(tag = "type", rename_all = "lowercase")] 262pub enum LexXrpcBodySchema<'s> { 263 // lexRefVariant 264 #[serde(borrow)] 265 Ref(LexRef<'s>), 266 Union(LexRefUnion<'s>), 267 // lexObject 268 Object(LexObject<'s>), 269} 270#[skip_serializing_none] 271#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 272pub struct LexXrpcBody<'s> { 273 #[serde(borrow)] 274 pub description: Option<CowStr<'s>>, 275 pub encoding: CowStr<'s>, 276 pub schema: Option<LexXrpcBodySchema<'s>>, 277} 278 279#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 280#[serde(tag = "type", rename_all = "lowercase")] 281pub enum LexXrpcSubscriptionMessageSchema<'s> { 282 // lexRefVariant 283 #[serde(borrow)] 284 Ref(LexRef<'s>), 285 Union(LexRefUnion<'s>), 286 // lexObject 287 Object(LexObject<'s>), 288} 289#[skip_serializing_none] 290#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 291pub struct LexXrpcSubscriptionMessage<'s> { 292 #[serde(borrow)] 293 pub description: Option<CowStr<'s>>, 294 pub schema: Option<LexXrpcSubscriptionMessageSchema<'s>>, 295} 296 297#[skip_serializing_none] 298#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 299pub struct LexXrpcError<'s> { 300 #[serde(borrow)] 301 pub description: Option<CowStr<'s>>, 302 pub name: CowStr<'s>, 303} 304 305#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 306#[serde(tag = "type", rename_all = "lowercase")] 307pub enum LexXrpcQueryParameter<'s> { 308 #[serde(borrow)] 309 Params(LexXrpcParameters<'s>), 310} 311#[skip_serializing_none] 312#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 313pub struct LexXrpcQuery<'s> { 314 #[serde(borrow)] 315 pub description: Option<CowStr<'s>>, 316 pub parameters: Option<LexXrpcQueryParameter<'s>>, 317 pub output: Option<LexXrpcBody<'s>>, 318 pub errors: Option<Vec<LexXrpcError<'s>>>, 319} 320 321#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 322#[serde(tag = "type", rename_all = "lowercase")] 323pub enum LexXrpcProcedureParameter<'s> { 324 #[serde(borrow)] 325 Params(LexXrpcParameters<'s>), 326} 327#[skip_serializing_none] 328#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 329pub struct LexXrpcProcedure<'s> { 330 #[serde(borrow)] 331 pub description: Option<CowStr<'s>>, 332 pub parameters: Option<LexXrpcProcedureParameter<'s>>, 333 pub input: Option<LexXrpcBody<'s>>, 334 pub output: Option<LexXrpcBody<'s>>, 335 pub errors: Option<Vec<LexXrpcError<'s>>>, 336} 337 338#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 339#[serde(tag = "type", rename_all = "lowercase")] 340pub enum LexXrpcSubscriptionParameter<'s> { 341 #[serde(borrow)] 342 Params(LexXrpcParameters<'s>), 343} 344#[skip_serializing_none] 345#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 346pub struct LexXrpcSubscription<'s> { 347 #[serde(borrow)] 348 pub description: Option<CowStr<'s>>, 349 pub parameters: Option<LexXrpcSubscriptionParameter<'s>>, 350 pub message: Option<LexXrpcSubscriptionMessage<'s>>, 351 pub infos: Option<Vec<LexXrpcError<'s>>>, 352 pub errors: Option<Vec<LexXrpcError<'s>>>, 353} 354 355// database 356 357#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 358#[serde(tag = "type", rename_all = "lowercase")] 359pub enum LexRecordRecord<'s> { 360 #[serde(borrow)] 361 Object(LexObject<'s>), 362} 363#[skip_serializing_none] 364#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 365pub struct LexRecord<'s> { 366 #[serde(borrow)] 367 pub description: Option<CowStr<'s>>, 368 pub key: Option<CowStr<'s>>, 369 pub record: LexRecordRecord<'s>, 370} 371 372// core 373 374#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] 375#[serde(tag = "type", rename_all = "kebab-case")] 376pub enum LexUserType<'s> { 377 // lexRecord 378 #[serde(borrow)] 379 Record(LexRecord<'s>), 380 // lexXrpcQuery 381 #[serde(rename = "query")] 382 XrpcQuery(LexXrpcQuery<'s>), 383 // lexXrpcProcedure 384 #[serde(rename = "procedure")] 385 XrpcProcedure(LexXrpcProcedure<'s>), 386 // lexXrpcSubscription 387 #[serde(rename = "subscription")] 388 XrpcSubscription(LexXrpcSubscription<'s>), 389 // lexBlob 390 Blob(LexBlob<'s>), 391 // lexArray 392 Array(LexArray<'s>), 393 // lexToken 394 Token(LexToken<'s>), 395 // lexObject 396 Object(LexObject<'s>), 397 // lexBoolean, 398 Boolean(LexBoolean<'s>), 399 // lexInteger, 400 Integer(LexInteger<'s>), 401 // lexString, 402 String(LexString<'s>), 403 // lexBytes 404 Bytes(LexBytes<'s>), 405 // lexCidLink 406 CidLink(LexCidLink<'s>), 407 // lexUnknown 408 Unknown(LexUnknown<'s>), 409} 410 411// IntoStatic implementations for all lexicon types 412// These enable converting borrowed lexicon docs to owned 'static versions 413 414#[allow(unused)] 415macro_rules! impl_into_static_for_lex_struct { 416 ($($ty:ident),+ $(,)?) => { 417 $( 418 impl IntoStatic for $ty<'_> { 419 type Output = $ty<'static>; 420 421 fn into_static(self) -> Self::Output { 422 let Self { 423 $(description,)? 424 ..$fields 425 } = self; 426 Self::Output { 427 $(description: description.into_static(),)? 428 ..$fields.into_static() 429 } 430 } 431 } 432 )+ 433 }; 434} 435 436// Simpler approach: just clone and convert each field 437impl IntoStatic for Lexicon { 438 type Output = Lexicon; 439 fn into_static(self) -> Self::Output { 440 self 441 } 442} 443 444impl IntoStatic for LexStringFormat { 445 type Output = LexStringFormat; 446 fn into_static(self) -> Self::Output { 447 self 448 } 449} 450 451impl IntoStatic for LexiconDoc<'_> { 452 type Output = LexiconDoc<'static>; 453 fn into_static(self) -> Self::Output { 454 LexiconDoc { 455 lexicon: self.lexicon, 456 id: self.id.into_static(), 457 revision: self.revision, 458 description: self.description.into_static(), 459 defs: self.defs.into_static(), 460 } 461 } 462} 463 464impl IntoStatic for LexBoolean<'_> { 465 type Output = LexBoolean<'static>; 466 fn into_static(self) -> Self::Output { 467 LexBoolean { 468 description: self.description.into_static(), 469 default: self.default, 470 r#const: self.r#const, 471 } 472 } 473} 474 475impl IntoStatic for LexInteger<'_> { 476 type Output = LexInteger<'static>; 477 fn into_static(self) -> Self::Output { 478 LexInteger { 479 description: self.description.into_static(), 480 default: self.default, 481 minimum: self.minimum, 482 maximum: self.maximum, 483 r#enum: self.r#enum, 484 r#const: self.r#const, 485 } 486 } 487} 488 489impl IntoStatic for LexString<'_> { 490 type Output = LexString<'static>; 491 fn into_static(self) -> Self::Output { 492 LexString { 493 description: self.description.into_static(), 494 format: self.format, 495 default: self.default.into_static(), 496 min_length: self.min_length, 497 max_length: self.max_length, 498 min_graphemes: self.min_graphemes, 499 max_graphemes: self.max_graphemes, 500 r#enum: self.r#enum.into_static(), 501 r#const: self.r#const.into_static(), 502 known_values: self.known_values.into_static(), 503 } 504 } 505} 506 507impl IntoStatic for LexUnknown<'_> { 508 type Output = LexUnknown<'static>; 509 fn into_static(self) -> Self::Output { 510 LexUnknown { 511 description: self.description.into_static(), 512 } 513 } 514} 515 516impl IntoStatic for LexBytes<'_> { 517 type Output = LexBytes<'static>; 518 fn into_static(self) -> Self::Output { 519 LexBytes { 520 description: self.description.into_static(), 521 max_length: self.max_length, 522 min_length: self.min_length, 523 } 524 } 525} 526 527impl IntoStatic for LexCidLink<'_> { 528 type Output = LexCidLink<'static>; 529 fn into_static(self) -> Self::Output { 530 LexCidLink { 531 description: self.description.into_static(), 532 } 533 } 534} 535 536impl IntoStatic for LexRef<'_> { 537 type Output = LexRef<'static>; 538 fn into_static(self) -> Self::Output { 539 LexRef { 540 description: self.description.into_static(), 541 r#ref: self.r#ref.into_static(), 542 } 543 } 544} 545 546impl IntoStatic for LexRefUnion<'_> { 547 type Output = LexRefUnion<'static>; 548 fn into_static(self) -> Self::Output { 549 LexRefUnion { 550 description: self.description.into_static(), 551 refs: self.refs.into_static(), 552 closed: self.closed, 553 } 554 } 555} 556 557impl IntoStatic for LexBlob<'_> { 558 type Output = LexBlob<'static>; 559 fn into_static(self) -> Self::Output { 560 LexBlob { 561 description: self.description.into_static(), 562 accept: self.accept.into_static(), 563 max_size: self.max_size, 564 } 565 } 566} 567 568impl IntoStatic for LexArrayItem<'_> { 569 type Output = LexArrayItem<'static>; 570 fn into_static(self) -> Self::Output { 571 match self { 572 Self::Boolean(x) => LexArrayItem::Boolean(x.into_static()), 573 Self::Integer(x) => LexArrayItem::Integer(x.into_static()), 574 Self::String(x) => LexArrayItem::String(x.into_static()), 575 Self::Unknown(x) => LexArrayItem::Unknown(x.into_static()), 576 Self::Bytes(x) => LexArrayItem::Bytes(x.into_static()), 577 Self::CidLink(x) => LexArrayItem::CidLink(x.into_static()), 578 Self::Blob(x) => LexArrayItem::Blob(x.into_static()), 579 Self::Object(x) => LexArrayItem::Object(x.into_static()), 580 Self::Ref(x) => LexArrayItem::Ref(x.into_static()), 581 Self::Union(x) => LexArrayItem::Union(x.into_static()), 582 } 583 } 584} 585 586impl IntoStatic for LexArray<'_> { 587 type Output = LexArray<'static>; 588 fn into_static(self) -> Self::Output { 589 LexArray { 590 description: self.description.into_static(), 591 items: self.items.into_static(), 592 min_length: self.min_length, 593 max_length: self.max_length, 594 } 595 } 596} 597 598impl IntoStatic for LexPrimitiveArrayItem<'_> { 599 type Output = LexPrimitiveArrayItem<'static>; 600 fn into_static(self) -> Self::Output { 601 match self { 602 Self::Boolean(x) => LexPrimitiveArrayItem::Boolean(x.into_static()), 603 Self::Integer(x) => LexPrimitiveArrayItem::Integer(x.into_static()), 604 Self::String(x) => LexPrimitiveArrayItem::String(x.into_static()), 605 Self::Unknown(x) => LexPrimitiveArrayItem::Unknown(x.into_static()), 606 } 607 } 608} 609 610impl IntoStatic for LexPrimitiveArray<'_> { 611 type Output = LexPrimitiveArray<'static>; 612 fn into_static(self) -> Self::Output { 613 LexPrimitiveArray { 614 description: self.description.into_static(), 615 items: self.items.into_static(), 616 min_length: self.min_length, 617 max_length: self.max_length, 618 } 619 } 620} 621 622impl IntoStatic for LexToken<'_> { 623 type Output = LexToken<'static>; 624 fn into_static(self) -> Self::Output { 625 LexToken { 626 description: self.description.into_static(), 627 } 628 } 629} 630 631impl IntoStatic for LexObjectProperty<'_> { 632 type Output = LexObjectProperty<'static>; 633 fn into_static(self) -> Self::Output { 634 match self { 635 Self::Ref(x) => LexObjectProperty::Ref(x.into_static()), 636 Self::Union(x) => LexObjectProperty::Union(x.into_static()), 637 Self::Bytes(x) => LexObjectProperty::Bytes(x.into_static()), 638 Self::CidLink(x) => LexObjectProperty::CidLink(x.into_static()), 639 Self::Array(x) => LexObjectProperty::Array(x.into_static()), 640 Self::Blob(x) => LexObjectProperty::Blob(x.into_static()), 641 Self::Object(x) => LexObjectProperty::Object(x.into_static()), 642 Self::Boolean(x) => LexObjectProperty::Boolean(x.into_static()), 643 Self::Integer(x) => LexObjectProperty::Integer(x.into_static()), 644 Self::String(x) => LexObjectProperty::String(x.into_static()), 645 Self::Unknown(x) => LexObjectProperty::Unknown(x.into_static()), 646 } 647 } 648} 649 650impl IntoStatic for LexObject<'_> { 651 type Output = LexObject<'static>; 652 fn into_static(self) -> Self::Output { 653 LexObject { 654 description: self.description.into_static(), 655 required: self.required, 656 nullable: self.nullable, 657 properties: self.properties.into_static(), 658 } 659 } 660} 661 662impl IntoStatic for LexXrpcParametersProperty<'_> { 663 type Output = LexXrpcParametersProperty<'static>; 664 fn into_static(self) -> Self::Output { 665 match self { 666 Self::Boolean(x) => LexXrpcParametersProperty::Boolean(x.into_static()), 667 Self::Integer(x) => LexXrpcParametersProperty::Integer(x.into_static()), 668 Self::String(x) => LexXrpcParametersProperty::String(x.into_static()), 669 Self::Unknown(x) => LexXrpcParametersProperty::Unknown(x.into_static()), 670 Self::Array(x) => LexXrpcParametersProperty::Array(x.into_static()), 671 } 672 } 673} 674 675impl IntoStatic for LexXrpcParameters<'_> { 676 type Output = LexXrpcParameters<'static>; 677 fn into_static(self) -> Self::Output { 678 LexXrpcParameters { 679 description: self.description.into_static(), 680 required: self.required, 681 properties: self.properties.into_static(), 682 } 683 } 684} 685 686impl IntoStatic for LexXrpcBodySchema<'_> { 687 type Output = LexXrpcBodySchema<'static>; 688 fn into_static(self) -> Self::Output { 689 match self { 690 Self::Ref(x) => LexXrpcBodySchema::Ref(x.into_static()), 691 Self::Union(x) => LexXrpcBodySchema::Union(x.into_static()), 692 Self::Object(x) => LexXrpcBodySchema::Object(x.into_static()), 693 } 694 } 695} 696 697impl IntoStatic for LexXrpcBody<'_> { 698 type Output = LexXrpcBody<'static>; 699 fn into_static(self) -> Self::Output { 700 LexXrpcBody { 701 description: self.description.into_static(), 702 encoding: self.encoding.into_static(), 703 schema: self.schema.into_static(), 704 } 705 } 706} 707 708impl IntoStatic for LexXrpcSubscriptionMessageSchema<'_> { 709 type Output = LexXrpcSubscriptionMessageSchema<'static>; 710 fn into_static(self) -> Self::Output { 711 match self { 712 Self::Ref(x) => LexXrpcSubscriptionMessageSchema::Ref(x.into_static()), 713 Self::Union(x) => LexXrpcSubscriptionMessageSchema::Union(x.into_static()), 714 Self::Object(x) => LexXrpcSubscriptionMessageSchema::Object(x.into_static()), 715 } 716 } 717} 718 719impl IntoStatic for LexXrpcSubscriptionMessage<'_> { 720 type Output = LexXrpcSubscriptionMessage<'static>; 721 fn into_static(self) -> Self::Output { 722 LexXrpcSubscriptionMessage { 723 description: self.description.into_static(), 724 schema: self.schema.into_static(), 725 } 726 } 727} 728 729impl IntoStatic for LexXrpcError<'_> { 730 type Output = LexXrpcError<'static>; 731 fn into_static(self) -> Self::Output { 732 LexXrpcError { 733 description: self.description.into_static(), 734 name: self.name.into_static(), 735 } 736 } 737} 738 739impl IntoStatic for LexXrpcQueryParameter<'_> { 740 type Output = LexXrpcQueryParameter<'static>; 741 fn into_static(self) -> Self::Output { 742 match self { 743 Self::Params(x) => LexXrpcQueryParameter::Params(x.into_static()), 744 } 745 } 746} 747 748impl IntoStatic for LexXrpcQuery<'_> { 749 type Output = LexXrpcQuery<'static>; 750 fn into_static(self) -> Self::Output { 751 LexXrpcQuery { 752 description: self.description.into_static(), 753 parameters: self.parameters.into_static(), 754 output: self.output.into_static(), 755 errors: self.errors.into_static(), 756 } 757 } 758} 759 760impl IntoStatic for LexXrpcProcedureParameter<'_> { 761 type Output = LexXrpcProcedureParameter<'static>; 762 fn into_static(self) -> Self::Output { 763 match self { 764 Self::Params(x) => LexXrpcProcedureParameter::Params(x.into_static()), 765 } 766 } 767} 768 769impl IntoStatic for LexXrpcProcedure<'_> { 770 type Output = LexXrpcProcedure<'static>; 771 fn into_static(self) -> Self::Output { 772 LexXrpcProcedure { 773 description: self.description.into_static(), 774 parameters: self.parameters.into_static(), 775 input: self.input.into_static(), 776 output: self.output.into_static(), 777 errors: self.errors.into_static(), 778 } 779 } 780} 781 782impl IntoStatic for LexXrpcSubscriptionParameter<'_> { 783 type Output = LexXrpcSubscriptionParameter<'static>; 784 fn into_static(self) -> Self::Output { 785 match self { 786 Self::Params(x) => LexXrpcSubscriptionParameter::Params(x.into_static()), 787 } 788 } 789} 790 791impl IntoStatic for LexXrpcSubscription<'_> { 792 type Output = LexXrpcSubscription<'static>; 793 fn into_static(self) -> Self::Output { 794 LexXrpcSubscription { 795 description: self.description.into_static(), 796 parameters: self.parameters.into_static(), 797 message: self.message.into_static(), 798 infos: self.infos.into_static(), 799 errors: self.errors.into_static(), 800 } 801 } 802} 803 804impl IntoStatic for LexRecordRecord<'_> { 805 type Output = LexRecordRecord<'static>; 806 fn into_static(self) -> Self::Output { 807 match self { 808 Self::Object(x) => LexRecordRecord::Object(x.into_static()), 809 } 810 } 811} 812 813impl IntoStatic for LexRecord<'_> { 814 type Output = LexRecord<'static>; 815 fn into_static(self) -> Self::Output { 816 LexRecord { 817 description: self.description.into_static(), 818 key: self.key.into_static(), 819 record: self.record.into_static(), 820 } 821 } 822} 823 824impl IntoStatic for LexUserType<'_> { 825 type Output = LexUserType<'static>; 826 fn into_static(self) -> Self::Output { 827 match self { 828 Self::Record(x) => LexUserType::Record(x.into_static()), 829 Self::XrpcQuery(x) => LexUserType::XrpcQuery(x.into_static()), 830 Self::XrpcProcedure(x) => LexUserType::XrpcProcedure(x.into_static()), 831 Self::XrpcSubscription(x) => LexUserType::XrpcSubscription(x.into_static()), 832 Self::Blob(x) => LexUserType::Blob(x.into_static()), 833 Self::Array(x) => LexUserType::Array(x.into_static()), 834 Self::Token(x) => LexUserType::Token(x.into_static()), 835 Self::Object(x) => LexUserType::Object(x.into_static()), 836 Self::Boolean(x) => LexUserType::Boolean(x.into_static()), 837 Self::Integer(x) => LexUserType::Integer(x.into_static()), 838 Self::String(x) => LexUserType::String(x.into_static()), 839 Self::Bytes(x) => LexUserType::Bytes(x.into_static()), 840 Self::CidLink(x) => LexUserType::CidLink(x.into_static()), 841 Self::Unknown(x) => LexUserType::Unknown(x.into_static()), 842 } 843 } 844} 845 846#[cfg(test)] 847mod tests { 848 use super::*; 849 850 const LEXICON_EXAMPLE_TOKEN: &str = r#" 851{ 852 "lexicon": 1, 853 "id": "com.socialapp.actorUser", 854 "defs": { 855 "main": { 856 "type": "token", 857 "description": "Actor type of 'User'" 858 } 859 } 860}"#; 861 862 #[test] 863 fn parse() { 864 let doc = serde_json::from_str::<LexiconDoc>(LEXICON_EXAMPLE_TOKEN) 865 .expect("failed to deserialize"); 866 assert_eq!(doc.lexicon, Lexicon::Lexicon1); 867 assert_eq!(doc.id, "com.socialapp.actorUser"); 868 assert_eq!(doc.revision, None); 869 assert_eq!(doc.description, None); 870 assert_eq!(doc.defs.len(), 1); 871 } 872}