// @generated by jacquard-lexicon. DO NOT EDIT. // // Lexicon: pub.leaflet.document // // This file was automatically generated from Lexicon schemas. // Any manual changes will be overwritten on the next regeneration. /// Record containing a document #[jacquard_derive::lexicon] #[derive( serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq, jacquard_derive::IntoStatic )] #[serde(rename_all = "camelCase")] pub struct Document<'a> { #[serde(borrow)] pub author: jacquard_common::types::ident::AtIdentifier<'a>, #[serde(skip_serializing_if = "std::option::Option::is_none")] #[serde(borrow)] pub description: std::option::Option>, #[serde(borrow)] pub pages: Vec>, #[serde(skip_serializing_if = "std::option::Option::is_none")] #[serde(borrow)] pub post_ref: std::option::Option< crate::com_atproto::repo::strong_ref::StrongRef<'a>, >, #[serde(skip_serializing_if = "std::option::Option::is_none")] #[serde(borrow)] pub publication: std::option::Option>, #[serde(skip_serializing_if = "std::option::Option::is_none")] pub published_at: std::option::Option, #[serde(skip_serializing_if = "std::option::Option::is_none")] #[serde(borrow)] pub tags: std::option::Option>>, #[serde(skip_serializing_if = "std::option::Option::is_none")] #[serde(borrow)] pub theme: std::option::Option>, #[serde(borrow)] pub title: jacquard_common::CowStr<'a>, } pub mod document_state { pub use crate::builder_types::{Set, Unset, IsSet, IsUnset}; #[allow(unused)] use ::core::marker::PhantomData; mod sealed { pub trait Sealed {} } /// State trait tracking which required fields have been set pub trait State: sealed::Sealed { type Title; type Pages; type Author; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type Title = Unset; type Pages = Unset; type Author = Unset; } ///State transition - sets the `title` field to Set pub struct SetTitle(PhantomData S>); impl sealed::Sealed for SetTitle {} impl State for SetTitle { type Title = Set; type Pages = S::Pages; type Author = S::Author; } ///State transition - sets the `pages` field to Set pub struct SetPages(PhantomData S>); impl sealed::Sealed for SetPages {} impl State for SetPages { type Title = S::Title; type Pages = Set; type Author = S::Author; } ///State transition - sets the `author` field to Set pub struct SetAuthor(PhantomData S>); impl sealed::Sealed for SetAuthor {} impl State for SetAuthor { type Title = S::Title; type Pages = S::Pages; type Author = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `title` field pub struct title(()); ///Marker type for the `pages` field pub struct pages(()); ///Marker type for the `author` field pub struct author(()); } } /// Builder for constructing an instance of this type pub struct DocumentBuilder<'a, S: document_state::State> { _phantom_state: ::core::marker::PhantomData S>, __unsafe_private_named: ( ::core::option::Option>, ::core::option::Option>, ::core::option::Option>>, ::core::option::Option>, ::core::option::Option>, ::core::option::Option, ::core::option::Option>>, ::core::option::Option>, ::core::option::Option>, ), _phantom: ::core::marker::PhantomData<&'a ()>, } impl<'a> Document<'a> { /// Create a new builder for this type pub fn new() -> DocumentBuilder<'a, document_state::Empty> { DocumentBuilder::new() } } impl<'a> DocumentBuilder<'a, document_state::Empty> { /// Create a new builder with all fields unset pub fn new() -> Self { DocumentBuilder { _phantom_state: ::core::marker::PhantomData, __unsafe_private_named: ( None, None, None, None, None, None, None, None, None, ), _phantom: ::core::marker::PhantomData, } } } impl<'a, S> DocumentBuilder<'a, S> where S: document_state::State, S::Author: document_state::IsUnset, { /// Set the `author` field (required) pub fn author( mut self, value: impl Into>, ) -> DocumentBuilder<'a, document_state::SetAuthor> { self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into()); DocumentBuilder { _phantom_state: ::core::marker::PhantomData, __unsafe_private_named: self.__unsafe_private_named, _phantom: ::core::marker::PhantomData, } } } impl<'a, S: document_state::State> DocumentBuilder<'a, S> { /// Set the `description` field (optional) pub fn description( mut self, value: impl Into>>, ) -> Self { self.__unsafe_private_named.1 = value.into(); self } /// Set the `description` field to an Option value (optional) pub fn maybe_description( mut self, value: Option>, ) -> Self { self.__unsafe_private_named.1 = value; self } } impl<'a, S> DocumentBuilder<'a, S> where S: document_state::State, S::Pages: document_state::IsUnset, { /// Set the `pages` field (required) pub fn pages( mut self, value: impl Into>>, ) -> DocumentBuilder<'a, document_state::SetPages> { self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into()); DocumentBuilder { _phantom_state: ::core::marker::PhantomData, __unsafe_private_named: self.__unsafe_private_named, _phantom: ::core::marker::PhantomData, } } } impl<'a, S: document_state::State> DocumentBuilder<'a, S> { /// Set the `postRef` field (optional) pub fn post_ref( mut self, value: impl Into>>, ) -> Self { self.__unsafe_private_named.3 = value.into(); self } /// Set the `postRef` field to an Option value (optional) pub fn maybe_post_ref( mut self, value: Option>, ) -> Self { self.__unsafe_private_named.3 = value; self } } impl<'a, S: document_state::State> DocumentBuilder<'a, S> { /// Set the `publication` field (optional) pub fn publication( mut self, value: impl Into>>, ) -> Self { self.__unsafe_private_named.4 = value.into(); self } /// Set the `publication` field to an Option value (optional) pub fn maybe_publication( mut self, value: Option>, ) -> Self { self.__unsafe_private_named.4 = value; self } } impl<'a, S: document_state::State> DocumentBuilder<'a, S> { /// Set the `publishedAt` field (optional) pub fn published_at( mut self, value: impl Into>, ) -> Self { self.__unsafe_private_named.5 = value.into(); self } /// Set the `publishedAt` field to an Option value (optional) pub fn maybe_published_at( mut self, value: Option, ) -> Self { self.__unsafe_private_named.5 = value; self } } impl<'a, S: document_state::State> DocumentBuilder<'a, S> { /// Set the `tags` field (optional) pub fn tags( mut self, value: impl Into>>>, ) -> Self { self.__unsafe_private_named.6 = value.into(); self } /// Set the `tags` field to an Option value (optional) pub fn maybe_tags( mut self, value: Option>>, ) -> Self { self.__unsafe_private_named.6 = value; self } } impl<'a, S: document_state::State> DocumentBuilder<'a, S> { /// Set the `theme` field (optional) pub fn theme( mut self, value: impl Into>>, ) -> Self { self.__unsafe_private_named.7 = value.into(); self } /// Set the `theme` field to an Option value (optional) pub fn maybe_theme( mut self, value: Option>, ) -> Self { self.__unsafe_private_named.7 = value; self } } impl<'a, S> DocumentBuilder<'a, S> where S: document_state::State, S::Title: document_state::IsUnset, { /// Set the `title` field (required) pub fn title( mut self, value: impl Into>, ) -> DocumentBuilder<'a, document_state::SetTitle> { self.__unsafe_private_named.8 = ::core::option::Option::Some(value.into()); DocumentBuilder { _phantom_state: ::core::marker::PhantomData, __unsafe_private_named: self.__unsafe_private_named, _phantom: ::core::marker::PhantomData, } } } impl<'a, S> DocumentBuilder<'a, S> where S: document_state::State, S::Title: document_state::IsSet, S::Pages: document_state::IsSet, S::Author: document_state::IsSet, { /// Build the final struct pub fn build(self) -> Document<'a> { Document { author: self.__unsafe_private_named.0.unwrap(), description: self.__unsafe_private_named.1, pages: self.__unsafe_private_named.2.unwrap(), post_ref: self.__unsafe_private_named.3, publication: self.__unsafe_private_named.4, published_at: self.__unsafe_private_named.5, tags: self.__unsafe_private_named.6, theme: self.__unsafe_private_named.7, title: self.__unsafe_private_named.8.unwrap(), extra_data: Default::default(), } } /// Build the final struct with custom extra_data pub fn build_with_data( self, extra_data: std::collections::BTreeMap< jacquard_common::smol_str::SmolStr, jacquard_common::types::value::Data<'a>, >, ) -> Document<'a> { Document { author: self.__unsafe_private_named.0.unwrap(), description: self.__unsafe_private_named.1, pages: self.__unsafe_private_named.2.unwrap(), post_ref: self.__unsafe_private_named.3, publication: self.__unsafe_private_named.4, published_at: self.__unsafe_private_named.5, tags: self.__unsafe_private_named.6, theme: self.__unsafe_private_named.7, title: self.__unsafe_private_named.8.unwrap(), extra_data: Some(extra_data), } } } impl<'a> Document<'a> { pub fn uri( uri: impl Into>, ) -> Result< jacquard_common::types::uri::RecordUri<'a, DocumentRecord>, jacquard_common::types::uri::UriError, > { jacquard_common::types::uri::RecordUri::try_from_uri( jacquard_common::types::string::AtUri::new_cow(uri.into())?, ) } } #[jacquard_derive::open_union] #[derive( serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq, jacquard_derive::IntoStatic )] #[serde(tag = "$type")] #[serde(bound(deserialize = "'de: 'a"))] pub enum DocumentPagesItem<'a> { #[serde(rename = "pub.leaflet.pages.linearDocument")] LinearDocument(Box>), #[serde(rename = "pub.leaflet.pages.canvas")] Canvas(Box>), } /// Typed wrapper for GetRecord response with this collection's record type. #[derive( serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq, jacquard_derive::IntoStatic )] #[serde(rename_all = "camelCase")] pub struct DocumentGetRecordOutput<'a> { #[serde(skip_serializing_if = "std::option::Option::is_none")] #[serde(borrow)] pub cid: std::option::Option>, #[serde(borrow)] pub uri: jacquard_common::types::string::AtUri<'a>, #[serde(borrow)] pub value: Document<'a>, } impl From> for Document<'_> { fn from(output: DocumentGetRecordOutput<'_>) -> Self { use jacquard_common::IntoStatic; output.value.into_static() } } impl jacquard_common::types::collection::Collection for Document<'_> { const NSID: &'static str = "pub.leaflet.document"; type Record = DocumentRecord; } /// Marker type for deserializing records from this collection. #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct DocumentRecord; impl jacquard_common::xrpc::XrpcResp for DocumentRecord { const NSID: &'static str = "pub.leaflet.document"; const ENCODING: &'static str = "application/json"; type Output<'de> = DocumentGetRecordOutput<'de>; type Err<'de> = jacquard_common::types::collection::RecordError<'de>; } impl jacquard_common::types::collection::Collection for DocumentRecord { const NSID: &'static str = "pub.leaflet.document"; type Record = DocumentRecord; } impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Document<'a> { fn nsid() -> &'static str { "pub.leaflet.document" } fn def_name() -> &'static str { "main" } fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> { lexicon_doc_pub_leaflet_document() } fn validate( &self, ) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> { if let Some(ref value) = self.description { #[allow(unused_comparisons)] if ::len(value.as_ref()) > 3000usize { return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength { path: ::jacquard_lexicon::validation::ValidationPath::from_field( "description", ), max: 3000usize, actual: ::len(value.as_ref()), }); } } if let Some(ref value) = self.description { { let count = ::unicode_segmentation::UnicodeSegmentation::graphemes( value.as_ref(), true, ) .count(); if count > 300usize { return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes { path: ::jacquard_lexicon::validation::ValidationPath::from_field( "description", ), max: 300usize, actual: count, }); } } } { let value = &self.title; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 1280usize { return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength { path: ::jacquard_lexicon::validation::ValidationPath::from_field( "title", ), max: 1280usize, actual: ::len(value.as_ref()), }); } } { let value = &self.title; { let count = ::unicode_segmentation::UnicodeSegmentation::graphemes( value.as_ref(), true, ) .count(); if count > 128usize { return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes { path: ::jacquard_lexicon::validation::ValidationPath::from_field( "title", ), max: 128usize, actual: count, }); } } } Ok(()) } } fn lexicon_doc_pub_leaflet_document() -> ::jacquard_lexicon::lexicon::LexiconDoc< 'static, > { ::jacquard_lexicon::lexicon::LexiconDoc { lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1, id: ::jacquard_common::CowStr::new_static("pub.leaflet.document"), revision: None, description: None, defs: { let mut map = ::alloc::collections::BTreeMap::new(); map.insert( ::jacquard_common::smol_str::SmolStr::new_static("main"), ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord { description: Some( ::jacquard_common::CowStr::new_static( "Record containing a document", ), ), key: Some(::jacquard_common::CowStr::new_static("tid")), record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject { description: None, required: Some( vec![ ::jacquard_common::smol_str::SmolStr::new_static("pages"), ::jacquard_common::smol_str::SmolStr::new_static("author"), ::jacquard_common::smol_str::SmolStr::new_static("title") ], ), nullable: None, properties: { #[allow(unused_mut)] let mut map = ::alloc::collections::BTreeMap::new(); map.insert( ::jacquard_common::smol_str::SmolStr::new_static("author"), ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString { description: None, format: Some( ::jacquard_lexicon::lexicon::LexStringFormat::AtIdentifier, ), default: None, min_length: None, max_length: None, min_graphemes: None, max_graphemes: None, r#enum: None, r#const: None, known_values: None, }), ); map.insert( ::jacquard_common::smol_str::SmolStr::new_static( "description", ), ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString { description: None, format: None, default: None, min_length: None, max_length: Some(3000usize), min_graphemes: None, max_graphemes: Some(300usize), r#enum: None, r#const: None, known_values: None, }), ); map.insert( ::jacquard_common::smol_str::SmolStr::new_static("pages"), ::jacquard_lexicon::lexicon::LexObjectProperty::Array(::jacquard_lexicon::lexicon::LexArray { description: None, items: ::jacquard_lexicon::lexicon::LexArrayItem::Union(::jacquard_lexicon::lexicon::LexRefUnion { description: None, refs: vec![ ::jacquard_common::CowStr::new_static("pub.leaflet.pages.linearDocument"), ::jacquard_common::CowStr::new_static("pub.leaflet.pages.canvas") ], closed: None, }), min_length: None, max_length: None, }), ); map.insert( ::jacquard_common::smol_str::SmolStr::new_static("postRef"), ::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef { description: None, r#ref: ::jacquard_common::CowStr::new_static( "com.atproto.repo.strongRef", ), }), ); map.insert( ::jacquard_common::smol_str::SmolStr::new_static( "publication", ), ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString { description: None, format: Some( ::jacquard_lexicon::lexicon::LexStringFormat::AtUri, ), default: None, min_length: None, max_length: None, min_graphemes: None, max_graphemes: None, r#enum: None, r#const: None, known_values: None, }), ); map.insert( ::jacquard_common::smol_str::SmolStr::new_static( "publishedAt", ), ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString { description: None, format: Some( ::jacquard_lexicon::lexicon::LexStringFormat::Datetime, ), default: None, min_length: None, max_length: None, min_graphemes: None, max_graphemes: None, r#enum: None, r#const: None, known_values: None, }), ); map.insert( ::jacquard_common::smol_str::SmolStr::new_static("tags"), ::jacquard_lexicon::lexicon::LexObjectProperty::Array(::jacquard_lexicon::lexicon::LexArray { description: None, items: ::jacquard_lexicon::lexicon::LexArrayItem::String(::jacquard_lexicon::lexicon::LexString { description: None, format: None, default: None, min_length: None, max_length: Some(50usize), min_graphemes: None, max_graphemes: None, r#enum: None, r#const: None, known_values: None, }), min_length: None, max_length: None, }), ); map.insert( ::jacquard_common::smol_str::SmolStr::new_static("theme"), ::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef { description: None, r#ref: ::jacquard_common::CowStr::new_static( "pub.leaflet.publication#theme", ), }), ); map.insert( ::jacquard_common::smol_str::SmolStr::new_static("title"), ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString { description: None, format: None, default: None, min_length: None, max_length: Some(1280usize), min_graphemes: None, max_graphemes: Some(128usize), r#enum: None, r#const: None, known_values: None, }), ); map }, }), }), ); map }, } }