A better Rust ATProto crate
102
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 249 lines 8.3 kB view raw
1// @generated by jacquard-lexicon. DO NOT EDIT. 2// 3// Lexicon: test.ns2.consumer 4// 5// This file was automatically generated from Lexicon schemas. 6// Any manual changes will be overwritten on the next regeneration. 7 8#[allow(unused_imports)] 9use alloc::collections::BTreeMap; 10 11#[allow(unused_imports)] 12use core::marker::PhantomData; 13use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr}; 14 15#[allow(unused_imports)] 16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation; 17use jacquard_common::deps::smol_str::SmolStr; 18use jacquard_common::types::value::Data; 19use jacquard_derive::IntoStatic; 20use jacquard_lexicon::lexicon::LexiconDoc; 21use jacquard_lexicon::schema::LexiconSchema; 22 23#[allow(unused_imports)] 24use jacquard_lexicon::validation::{ConstraintError, ValidationPath}; 25use serde::{Serialize, Deserialize}; 26use crate::pretty::test_ns1::Bar; 27use crate::pretty::test_ns1::Foo; 28/// An object that references types across namespaces. 29 30#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] 31#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))] 32pub struct Consumer<S: BosStr = DefaultStr> { 33 #[serde(skip_serializing_if = "Option::is_none")] 34 pub description: Option<S>, 35 pub item: Foo<S>, 36 #[serde(skip_serializing_if = "Option::is_none")] 37 pub tags: Option<Vec<Bar<S>>>, 38 #[serde(flatten, default, skip_serializing_if = "Option::is_none")] 39 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>, 40} 41 42impl<S: BosStr> LexiconSchema for Consumer<S> { 43 fn nsid() -> &'static str { 44 "test.ns2.consumer" 45 } 46 fn def_name() -> &'static str { 47 "main" 48 } 49 fn lexicon_doc() -> LexiconDoc<'static> { 50 lexicon_doc_test_ns2_consumer() 51 } 52 fn validate(&self) -> Result<(), ConstraintError> { 53 if let Some(ref value) = self.description { 54 #[allow(unused_comparisons)] 55 if <str>::len(value.as_ref()) > 500usize { 56 return Err(ConstraintError::MaxLength { 57 path: ValidationPath::from_field("description"), 58 max: 500usize, 59 actual: <str>::len(value.as_ref()), 60 }); 61 } 62 } 63 Ok(()) 64 } 65} 66 67pub mod consumer_state { 68 69 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset}; 70 #[allow(unused)] 71 use ::core::marker::PhantomData; 72 mod sealed { 73 pub trait Sealed {} 74 } 75 /// State trait tracking which required fields have been set 76 pub trait State: sealed::Sealed { 77 type Item; 78 } 79 /// Empty state - all required fields are unset 80 pub struct Empty(()); 81 impl sealed::Sealed for Empty {} 82 impl State for Empty { 83 type Item = Unset; 84 } 85 ///State transition - sets the `item` field to Set 86 pub struct SetItem<St: State = Empty>(PhantomData<fn() -> St>); 87 impl<St: State> sealed::Sealed for SetItem<St> {} 88 impl<St: State> State for SetItem<St> { 89 type Item = Set<members::item>; 90 } 91 /// Marker types for field names 92 #[allow(non_camel_case_types)] 93 pub mod members { 94 ///Marker type for the `item` field 95 pub struct item(()); 96 } 97} 98 99/// Builder for constructing an instance of this type. 100pub struct ConsumerBuilder<S: BosStr, St: consumer_state::State> { 101 _state: PhantomData<fn() -> St>, 102 _fields: (Option<S>, Option<Foo<S>>, Option<Vec<Bar<S>>>), 103 _type: PhantomData<fn() -> S>, 104} 105 106impl<S: BosStr> Consumer<S> { 107 /// Create a new builder for this type. 108 pub fn new() -> ConsumerBuilder<S, consumer_state::Empty> { 109 ConsumerBuilder::new() 110 } 111} 112 113impl<S: BosStr> ConsumerBuilder<S, consumer_state::Empty> { 114 /// Create a new builder with all fields unset. 115 pub fn new() -> Self { 116 ConsumerBuilder { 117 _state: PhantomData, 118 _fields: (None, None, None), 119 _type: PhantomData, 120 } 121 } 122} 123 124impl<S: BosStr, St: consumer_state::State> ConsumerBuilder<S, St> { 125 /// Set the `description` field (optional) 126 pub fn description(mut self, value: impl Into<Option<S>>) -> Self { 127 self._fields.0 = value.into(); 128 self 129 } 130 /// Set the `description` field to an Option value (optional) 131 pub fn maybe_description(mut self, value: Option<S>) -> Self { 132 self._fields.0 = value; 133 self 134 } 135} 136 137impl<S: BosStr, St> ConsumerBuilder<S, St> 138where 139 St: consumer_state::State, 140 St::Item: consumer_state::IsUnset, 141{ 142 /// Set the `item` field (required) 143 pub fn item( 144 mut self, 145 value: impl Into<Foo<S>>, 146 ) -> ConsumerBuilder<S, consumer_state::SetItem<St>> { 147 self._fields.1 = Option::Some(value.into()); 148 ConsumerBuilder { 149 _state: PhantomData, 150 _fields: self._fields, 151 _type: PhantomData, 152 } 153 } 154} 155 156impl<S: BosStr, St: consumer_state::State> ConsumerBuilder<S, St> { 157 /// Set the `tags` field (optional) 158 pub fn tags(mut self, value: impl Into<Option<Vec<Bar<S>>>>) -> Self { 159 self._fields.2 = value.into(); 160 self 161 } 162 /// Set the `tags` field to an Option value (optional) 163 pub fn maybe_tags(mut self, value: Option<Vec<Bar<S>>>) -> Self { 164 self._fields.2 = value; 165 self 166 } 167} 168 169impl<S: BosStr, St> ConsumerBuilder<S, St> 170where 171 St: consumer_state::State, 172 St::Item: consumer_state::IsSet, 173{ 174 /// Build the final struct. 175 pub fn build(self) -> Consumer<S> { 176 Consumer { 177 description: self._fields.0, 178 item: self._fields.1.unwrap(), 179 tags: self._fields.2, 180 extra_data: Default::default(), 181 } 182 } 183 /// Build the final struct with custom extra_data. 184 pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Consumer<S> { 185 Consumer { 186 description: self._fields.0, 187 item: self._fields.1.unwrap(), 188 tags: self._fields.2, 189 extra_data: Some(extra_data), 190 } 191 } 192} 193 194fn lexicon_doc_test_ns2_consumer() -> LexiconDoc<'static> { 195 #[allow(unused_imports)] 196 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType}; 197 use jacquard_lexicon::lexicon::*; 198 use alloc::collections::BTreeMap; 199 LexiconDoc { 200 lexicon: Lexicon::Lexicon1, 201 id: CowStr::new_static("test.ns2.consumer"), 202 defs: { 203 let mut map = BTreeMap::new(); 204 map.insert( 205 SmolStr::new_static("main"), 206 LexUserType::Object(LexObject { 207 description: Some( 208 CowStr::new_static( 209 "An object that references types across namespaces.", 210 ), 211 ), 212 required: Some(vec![SmolStr::new_static("item")]), 213 properties: { 214 #[allow(unused_mut)] 215 let mut map = BTreeMap::new(); 216 map.insert( 217 SmolStr::new_static("description"), 218 LexObjectProperty::String(LexString { 219 max_length: Some(500usize), 220 ..Default::default() 221 }), 222 ); 223 map.insert( 224 SmolStr::new_static("item"), 225 LexObjectProperty::Ref(LexRef { 226 r#ref: CowStr::new_static("test.ns1.defs#foo"), 227 ..Default::default() 228 }), 229 ); 230 map.insert( 231 SmolStr::new_static("tags"), 232 LexObjectProperty::Array(LexArray { 233 items: LexArrayItem::Ref(LexRef { 234 r#ref: CowStr::new_static("test.ns1.defs#bar"), 235 ..Default::default() 236 }), 237 ..Default::default() 238 }), 239 ); 240 map 241 }, 242 ..Default::default() 243 }), 244 ); 245 map 246 }, 247 ..Default::default() 248 } 249}