A better Rust ATProto crate
at main 875 lines 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 // lexRefUnion 410 Union(LexRefUnion<'s>), 411} 412 413// IntoStatic implementations for all lexicon types 414// These enable converting borrowed lexicon docs to owned 'static versions 415 416#[allow(unused)] 417macro_rules! impl_into_static_for_lex_struct { 418 ($($ty:ident),+ $(,)?) => { 419 $( 420 impl IntoStatic for $ty<'_> { 421 type Output = $ty<'static>; 422 423 fn into_static(self) -> Self::Output { 424 let Self { 425 $(description,)? 426 ..$fields 427 } = self; 428 Self::Output { 429 $(description: description.into_static(),)? 430 ..$fields.into_static() 431 } 432 } 433 } 434 )+ 435 }; 436} 437 438// Simpler approach: just clone and convert each field 439impl IntoStatic for Lexicon { 440 type Output = Lexicon; 441 fn into_static(self) -> Self::Output { 442 self 443 } 444} 445 446impl IntoStatic for LexStringFormat { 447 type Output = LexStringFormat; 448 fn into_static(self) -> Self::Output { 449 self 450 } 451} 452 453impl IntoStatic for LexiconDoc<'_> { 454 type Output = LexiconDoc<'static>; 455 fn into_static(self) -> Self::Output { 456 LexiconDoc { 457 lexicon: self.lexicon, 458 id: self.id.into_static(), 459 revision: self.revision, 460 description: self.description.into_static(), 461 defs: self.defs.into_static(), 462 } 463 } 464} 465 466impl IntoStatic for LexBoolean<'_> { 467 type Output = LexBoolean<'static>; 468 fn into_static(self) -> Self::Output { 469 LexBoolean { 470 description: self.description.into_static(), 471 default: self.default, 472 r#const: self.r#const, 473 } 474 } 475} 476 477impl IntoStatic for LexInteger<'_> { 478 type Output = LexInteger<'static>; 479 fn into_static(self) -> Self::Output { 480 LexInteger { 481 description: self.description.into_static(), 482 default: self.default, 483 minimum: self.minimum, 484 maximum: self.maximum, 485 r#enum: self.r#enum, 486 r#const: self.r#const, 487 } 488 } 489} 490 491impl IntoStatic for LexString<'_> { 492 type Output = LexString<'static>; 493 fn into_static(self) -> Self::Output { 494 LexString { 495 description: self.description.into_static(), 496 format: self.format, 497 default: self.default.into_static(), 498 min_length: self.min_length, 499 max_length: self.max_length, 500 min_graphemes: self.min_graphemes, 501 max_graphemes: self.max_graphemes, 502 r#enum: self.r#enum.into_static(), 503 r#const: self.r#const.into_static(), 504 known_values: self.known_values.into_static(), 505 } 506 } 507} 508 509impl IntoStatic for LexUnknown<'_> { 510 type Output = LexUnknown<'static>; 511 fn into_static(self) -> Self::Output { 512 LexUnknown { 513 description: self.description.into_static(), 514 } 515 } 516} 517 518impl IntoStatic for LexBytes<'_> { 519 type Output = LexBytes<'static>; 520 fn into_static(self) -> Self::Output { 521 LexBytes { 522 description: self.description.into_static(), 523 max_length: self.max_length, 524 min_length: self.min_length, 525 } 526 } 527} 528 529impl IntoStatic for LexCidLink<'_> { 530 type Output = LexCidLink<'static>; 531 fn into_static(self) -> Self::Output { 532 LexCidLink { 533 description: self.description.into_static(), 534 } 535 } 536} 537 538impl IntoStatic for LexRef<'_> { 539 type Output = LexRef<'static>; 540 fn into_static(self) -> Self::Output { 541 LexRef { 542 description: self.description.into_static(), 543 r#ref: self.r#ref.into_static(), 544 } 545 } 546} 547 548impl IntoStatic for LexRefUnion<'_> { 549 type Output = LexRefUnion<'static>; 550 fn into_static(self) -> Self::Output { 551 LexRefUnion { 552 description: self.description.into_static(), 553 refs: self.refs.into_static(), 554 closed: self.closed, 555 } 556 } 557} 558 559impl IntoStatic for LexBlob<'_> { 560 type Output = LexBlob<'static>; 561 fn into_static(self) -> Self::Output { 562 LexBlob { 563 description: self.description.into_static(), 564 accept: self.accept.into_static(), 565 max_size: self.max_size, 566 } 567 } 568} 569 570impl IntoStatic for LexArrayItem<'_> { 571 type Output = LexArrayItem<'static>; 572 fn into_static(self) -> Self::Output { 573 match self { 574 Self::Boolean(x) => LexArrayItem::Boolean(x.into_static()), 575 Self::Integer(x) => LexArrayItem::Integer(x.into_static()), 576 Self::String(x) => LexArrayItem::String(x.into_static()), 577 Self::Unknown(x) => LexArrayItem::Unknown(x.into_static()), 578 Self::Bytes(x) => LexArrayItem::Bytes(x.into_static()), 579 Self::CidLink(x) => LexArrayItem::CidLink(x.into_static()), 580 Self::Blob(x) => LexArrayItem::Blob(x.into_static()), 581 Self::Object(x) => LexArrayItem::Object(x.into_static()), 582 Self::Ref(x) => LexArrayItem::Ref(x.into_static()), 583 Self::Union(x) => LexArrayItem::Union(x.into_static()), 584 } 585 } 586} 587 588impl IntoStatic for LexArray<'_> { 589 type Output = LexArray<'static>; 590 fn into_static(self) -> Self::Output { 591 LexArray { 592 description: self.description.into_static(), 593 items: self.items.into_static(), 594 min_length: self.min_length, 595 max_length: self.max_length, 596 } 597 } 598} 599 600impl IntoStatic for LexPrimitiveArrayItem<'_> { 601 type Output = LexPrimitiveArrayItem<'static>; 602 fn into_static(self) -> Self::Output { 603 match self { 604 Self::Boolean(x) => LexPrimitiveArrayItem::Boolean(x.into_static()), 605 Self::Integer(x) => LexPrimitiveArrayItem::Integer(x.into_static()), 606 Self::String(x) => LexPrimitiveArrayItem::String(x.into_static()), 607 Self::Unknown(x) => LexPrimitiveArrayItem::Unknown(x.into_static()), 608 } 609 } 610} 611 612impl IntoStatic for LexPrimitiveArray<'_> { 613 type Output = LexPrimitiveArray<'static>; 614 fn into_static(self) -> Self::Output { 615 LexPrimitiveArray { 616 description: self.description.into_static(), 617 items: self.items.into_static(), 618 min_length: self.min_length, 619 max_length: self.max_length, 620 } 621 } 622} 623 624impl IntoStatic for LexToken<'_> { 625 type Output = LexToken<'static>; 626 fn into_static(self) -> Self::Output { 627 LexToken { 628 description: self.description.into_static(), 629 } 630 } 631} 632 633impl IntoStatic for LexObjectProperty<'_> { 634 type Output = LexObjectProperty<'static>; 635 fn into_static(self) -> Self::Output { 636 match self { 637 Self::Ref(x) => LexObjectProperty::Ref(x.into_static()), 638 Self::Union(x) => LexObjectProperty::Union(x.into_static()), 639 Self::Bytes(x) => LexObjectProperty::Bytes(x.into_static()), 640 Self::CidLink(x) => LexObjectProperty::CidLink(x.into_static()), 641 Self::Array(x) => LexObjectProperty::Array(x.into_static()), 642 Self::Blob(x) => LexObjectProperty::Blob(x.into_static()), 643 Self::Object(x) => LexObjectProperty::Object(x.into_static()), 644 Self::Boolean(x) => LexObjectProperty::Boolean(x.into_static()), 645 Self::Integer(x) => LexObjectProperty::Integer(x.into_static()), 646 Self::String(x) => LexObjectProperty::String(x.into_static()), 647 Self::Unknown(x) => LexObjectProperty::Unknown(x.into_static()), 648 } 649 } 650} 651 652impl IntoStatic for LexObject<'_> { 653 type Output = LexObject<'static>; 654 fn into_static(self) -> Self::Output { 655 LexObject { 656 description: self.description.into_static(), 657 required: self.required, 658 nullable: self.nullable, 659 properties: self.properties.into_static(), 660 } 661 } 662} 663 664impl IntoStatic for LexXrpcParametersProperty<'_> { 665 type Output = LexXrpcParametersProperty<'static>; 666 fn into_static(self) -> Self::Output { 667 match self { 668 Self::Boolean(x) => LexXrpcParametersProperty::Boolean(x.into_static()), 669 Self::Integer(x) => LexXrpcParametersProperty::Integer(x.into_static()), 670 Self::String(x) => LexXrpcParametersProperty::String(x.into_static()), 671 Self::Unknown(x) => LexXrpcParametersProperty::Unknown(x.into_static()), 672 Self::Array(x) => LexXrpcParametersProperty::Array(x.into_static()), 673 } 674 } 675} 676 677impl IntoStatic for LexXrpcParameters<'_> { 678 type Output = LexXrpcParameters<'static>; 679 fn into_static(self) -> Self::Output { 680 LexXrpcParameters { 681 description: self.description.into_static(), 682 required: self.required, 683 properties: self.properties.into_static(), 684 } 685 } 686} 687 688impl IntoStatic for LexXrpcBodySchema<'_> { 689 type Output = LexXrpcBodySchema<'static>; 690 fn into_static(self) -> Self::Output { 691 match self { 692 Self::Ref(x) => LexXrpcBodySchema::Ref(x.into_static()), 693 Self::Union(x) => LexXrpcBodySchema::Union(x.into_static()), 694 Self::Object(x) => LexXrpcBodySchema::Object(x.into_static()), 695 } 696 } 697} 698 699impl IntoStatic for LexXrpcBody<'_> { 700 type Output = LexXrpcBody<'static>; 701 fn into_static(self) -> Self::Output { 702 LexXrpcBody { 703 description: self.description.into_static(), 704 encoding: self.encoding.into_static(), 705 schema: self.schema.into_static(), 706 } 707 } 708} 709 710impl IntoStatic for LexXrpcSubscriptionMessageSchema<'_> { 711 type Output = LexXrpcSubscriptionMessageSchema<'static>; 712 fn into_static(self) -> Self::Output { 713 match self { 714 Self::Ref(x) => LexXrpcSubscriptionMessageSchema::Ref(x.into_static()), 715 Self::Union(x) => LexXrpcSubscriptionMessageSchema::Union(x.into_static()), 716 Self::Object(x) => LexXrpcSubscriptionMessageSchema::Object(x.into_static()), 717 } 718 } 719} 720 721impl IntoStatic for LexXrpcSubscriptionMessage<'_> { 722 type Output = LexXrpcSubscriptionMessage<'static>; 723 fn into_static(self) -> Self::Output { 724 LexXrpcSubscriptionMessage { 725 description: self.description.into_static(), 726 schema: self.schema.into_static(), 727 } 728 } 729} 730 731impl IntoStatic for LexXrpcError<'_> { 732 type Output = LexXrpcError<'static>; 733 fn into_static(self) -> Self::Output { 734 LexXrpcError { 735 description: self.description.into_static(), 736 name: self.name.into_static(), 737 } 738 } 739} 740 741impl IntoStatic for LexXrpcQueryParameter<'_> { 742 type Output = LexXrpcQueryParameter<'static>; 743 fn into_static(self) -> Self::Output { 744 match self { 745 Self::Params(x) => LexXrpcQueryParameter::Params(x.into_static()), 746 } 747 } 748} 749 750impl IntoStatic for LexXrpcQuery<'_> { 751 type Output = LexXrpcQuery<'static>; 752 fn into_static(self) -> Self::Output { 753 LexXrpcQuery { 754 description: self.description.into_static(), 755 parameters: self.parameters.into_static(), 756 output: self.output.into_static(), 757 errors: self.errors.into_static(), 758 } 759 } 760} 761 762impl IntoStatic for LexXrpcProcedureParameter<'_> { 763 type Output = LexXrpcProcedureParameter<'static>; 764 fn into_static(self) -> Self::Output { 765 match self { 766 Self::Params(x) => LexXrpcProcedureParameter::Params(x.into_static()), 767 } 768 } 769} 770 771impl IntoStatic for LexXrpcProcedure<'_> { 772 type Output = LexXrpcProcedure<'static>; 773 fn into_static(self) -> Self::Output { 774 LexXrpcProcedure { 775 description: self.description.into_static(), 776 parameters: self.parameters.into_static(), 777 input: self.input.into_static(), 778 output: self.output.into_static(), 779 errors: self.errors.into_static(), 780 } 781 } 782} 783 784impl IntoStatic for LexXrpcSubscriptionParameter<'_> { 785 type Output = LexXrpcSubscriptionParameter<'static>; 786 fn into_static(self) -> Self::Output { 787 match self { 788 Self::Params(x) => LexXrpcSubscriptionParameter::Params(x.into_static()), 789 } 790 } 791} 792 793impl IntoStatic for LexXrpcSubscription<'_> { 794 type Output = LexXrpcSubscription<'static>; 795 fn into_static(self) -> Self::Output { 796 LexXrpcSubscription { 797 description: self.description.into_static(), 798 parameters: self.parameters.into_static(), 799 message: self.message.into_static(), 800 infos: self.infos.into_static(), 801 errors: self.errors.into_static(), 802 } 803 } 804} 805 806impl IntoStatic for LexRecordRecord<'_> { 807 type Output = LexRecordRecord<'static>; 808 fn into_static(self) -> Self::Output { 809 match self { 810 Self::Object(x) => LexRecordRecord::Object(x.into_static()), 811 } 812 } 813} 814 815impl IntoStatic for LexRecord<'_> { 816 type Output = LexRecord<'static>; 817 fn into_static(self) -> Self::Output { 818 LexRecord { 819 description: self.description.into_static(), 820 key: self.key.into_static(), 821 record: self.record.into_static(), 822 } 823 } 824} 825 826impl IntoStatic for LexUserType<'_> { 827 type Output = LexUserType<'static>; 828 fn into_static(self) -> Self::Output { 829 match self { 830 Self::Record(x) => LexUserType::Record(x.into_static()), 831 Self::XrpcQuery(x) => LexUserType::XrpcQuery(x.into_static()), 832 Self::XrpcProcedure(x) => LexUserType::XrpcProcedure(x.into_static()), 833 Self::XrpcSubscription(x) => LexUserType::XrpcSubscription(x.into_static()), 834 Self::Blob(x) => LexUserType::Blob(x.into_static()), 835 Self::Array(x) => LexUserType::Array(x.into_static()), 836 Self::Token(x) => LexUserType::Token(x.into_static()), 837 Self::Object(x) => LexUserType::Object(x.into_static()), 838 Self::Boolean(x) => LexUserType::Boolean(x.into_static()), 839 Self::Integer(x) => LexUserType::Integer(x.into_static()), 840 Self::String(x) => LexUserType::String(x.into_static()), 841 Self::Bytes(x) => LexUserType::Bytes(x.into_static()), 842 Self::CidLink(x) => LexUserType::CidLink(x.into_static()), 843 Self::Unknown(x) => LexUserType::Unknown(x.into_static()), 844 Self::Union(x) => LexUserType::Union(x.into_static()), 845 } 846 } 847} 848 849#[cfg(test)] 850mod tests { 851 use super::*; 852 853 const LEXICON_EXAMPLE_TOKEN: &str = r#" 854{ 855 "lexicon": 1, 856 "id": "com.socialapp.actorUser", 857 "defs": { 858 "main": { 859 "type": "token", 860 "description": "Actor type of 'User'" 861 } 862 } 863}"#; 864 865 #[test] 866 fn parse() { 867 let doc = serde_json::from_str::<LexiconDoc>(LEXICON_EXAMPLE_TOKEN) 868 .expect("failed to deserialize"); 869 assert_eq!(doc.lexicon, Lexicon::Lexicon1); 870 assert_eq!(doc.id, "com.socialapp.actorUser"); 871 assert_eq!(doc.revision, None); 872 assert_eq!(doc.description, None); 873 assert_eq!(doc.defs.len(), 1); 874 } 875}