A better Rust ATProto crate
102
fork

Configure Feed

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

at main 370 lines 13 kB view raw
1// @generated by jacquard-lexicon. DO NOT EDIT. 2// 3// Lexicon: test.collision.did 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_collision::did; 27/// A locally-defined type named Did that collides with the string import. 28 29#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)] 30#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))] 31pub struct Did<S: BosStr = DefaultStr> { 32 ///The DID method (e.g., plc, web). 33 pub method: S, 34 ///The full DID string. 35 pub value: S, 36 #[serde(flatten, default, skip_serializing_if = "Option::is_none")] 37 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>, 38} 39 40/// An object that also uses a DID-format string field, exercising the collision path. 41 42#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] 43#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))] 44pub struct DidRecord<S: BosStr = DefaultStr> { 45 pub identifier: did::Did<S>, 46 #[serde(skip_serializing_if = "Option::is_none")] 47 pub label: Option<S>, 48 ///A field typed as DID format, requiring the Did import but colliding with local Did type. 49 pub owner: jacquard_common::types::string::Did<S>, 50 #[serde(flatten, default, skip_serializing_if = "Option::is_none")] 51 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>, 52} 53 54impl<S: BosStr> LexiconSchema for Did<S> { 55 fn nsid() -> &'static str { 56 "test.collision.did" 57 } 58 fn def_name() -> &'static str { 59 "did" 60 } 61 fn lexicon_doc() -> LexiconDoc<'static> { 62 lexicon_doc_test_collision_did() 63 } 64 fn validate(&self) -> Result<(), ConstraintError> { 65 { 66 let value = &self.method; 67 #[allow(unused_comparisons)] 68 if <str>::len(value.as_ref()) > 50usize { 69 return Err(ConstraintError::MaxLength { 70 path: ValidationPath::from_field("method"), 71 max: 50usize, 72 actual: <str>::len(value.as_ref()), 73 }); 74 } 75 } 76 { 77 let value = &self.value; 78 #[allow(unused_comparisons)] 79 if <str>::len(value.as_ref()) > 256usize { 80 return Err(ConstraintError::MaxLength { 81 path: ValidationPath::from_field("value"), 82 max: 256usize, 83 actual: <str>::len(value.as_ref()), 84 }); 85 } 86 } 87 Ok(()) 88 } 89} 90 91impl<S: BosStr> LexiconSchema for DidRecord<S> { 92 fn nsid() -> &'static str { 93 "test.collision.did" 94 } 95 fn def_name() -> &'static str { 96 "main" 97 } 98 fn lexicon_doc() -> LexiconDoc<'static> { 99 lexicon_doc_test_collision_did() 100 } 101 fn validate(&self) -> Result<(), ConstraintError> { 102 if let Some(ref value) = self.label { 103 #[allow(unused_comparisons)] 104 if <str>::len(value.as_ref()) > 200usize { 105 return Err(ConstraintError::MaxLength { 106 path: ValidationPath::from_field("label"), 107 max: 200usize, 108 actual: <str>::len(value.as_ref()), 109 }); 110 } 111 } 112 Ok(()) 113 } 114} 115 116fn lexicon_doc_test_collision_did() -> LexiconDoc<'static> { 117 #[allow(unused_imports)] 118 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType}; 119 use jacquard_lexicon::lexicon::*; 120 use alloc::collections::BTreeMap; 121 LexiconDoc { 122 lexicon: Lexicon::Lexicon1, 123 id: CowStr::new_static("test.collision.did"), 124 defs: { 125 let mut map = BTreeMap::new(); 126 map.insert( 127 SmolStr::new_static("did"), 128 LexUserType::Object(LexObject { 129 description: Some( 130 CowStr::new_static( 131 "A locally-defined type named Did that collides with the string import.", 132 ), 133 ), 134 required: Some( 135 vec![SmolStr::new_static("method"), SmolStr::new_static("value")], 136 ), 137 properties: { 138 #[allow(unused_mut)] 139 let mut map = BTreeMap::new(); 140 map.insert( 141 SmolStr::new_static("method"), 142 LexObjectProperty::String(LexString { 143 description: Some( 144 CowStr::new_static("The DID method (e.g., plc, web)."), 145 ), 146 max_length: Some(50usize), 147 ..Default::default() 148 }), 149 ); 150 map.insert( 151 SmolStr::new_static("value"), 152 LexObjectProperty::String(LexString { 153 description: Some( 154 CowStr::new_static("The full DID string."), 155 ), 156 max_length: Some(256usize), 157 ..Default::default() 158 }), 159 ); 160 map 161 }, 162 ..Default::default() 163 }), 164 ); 165 map.insert( 166 SmolStr::new_static("main"), 167 LexUserType::Object(LexObject { 168 description: Some( 169 CowStr::new_static( 170 "An object that also uses a DID-format string field, exercising the collision path.", 171 ), 172 ), 173 required: Some( 174 vec![ 175 SmolStr::new_static("owner"), 176 SmolStr::new_static("identifier") 177 ], 178 ), 179 properties: { 180 #[allow(unused_mut)] 181 let mut map = BTreeMap::new(); 182 map.insert( 183 SmolStr::new_static("identifier"), 184 LexObjectProperty::Ref(LexRef { 185 r#ref: CowStr::new_static("#did"), 186 ..Default::default() 187 }), 188 ); 189 map.insert( 190 SmolStr::new_static("label"), 191 LexObjectProperty::String(LexString { 192 max_length: Some(200usize), 193 ..Default::default() 194 }), 195 ); 196 map.insert( 197 SmolStr::new_static("owner"), 198 LexObjectProperty::String(LexString { 199 description: Some( 200 CowStr::new_static( 201 "A field typed as DID format, requiring the Did import but colliding with local Did type.", 202 ), 203 ), 204 format: Some(LexStringFormat::Did), 205 ..Default::default() 206 }), 207 ); 208 map 209 }, 210 ..Default::default() 211 }), 212 ); 213 map 214 }, 215 ..Default::default() 216 } 217} 218 219pub mod did_record_state { 220 221 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset}; 222 #[allow(unused)] 223 use ::core::marker::PhantomData; 224 mod sealed { 225 pub trait Sealed {} 226 } 227 /// State trait tracking which required fields have been set 228 pub trait State: sealed::Sealed { 229 type Owner; 230 type Identifier; 231 } 232 /// Empty state - all required fields are unset 233 pub struct Empty(()); 234 impl sealed::Sealed for Empty {} 235 impl State for Empty { 236 type Owner = Unset; 237 type Identifier = Unset; 238 } 239 ///State transition - sets the `owner` field to Set 240 pub struct SetOwner<St: State = Empty>(PhantomData<fn() -> St>); 241 impl<St: State> sealed::Sealed for SetOwner<St> {} 242 impl<St: State> State for SetOwner<St> { 243 type Owner = Set<members::owner>; 244 type Identifier = St::Identifier; 245 } 246 ///State transition - sets the `identifier` field to Set 247 pub struct SetIdentifier<St: State = Empty>(PhantomData<fn() -> St>); 248 impl<St: State> sealed::Sealed for SetIdentifier<St> {} 249 impl<St: State> State for SetIdentifier<St> { 250 type Owner = St::Owner; 251 type Identifier = Set<members::identifier>; 252 } 253 /// Marker types for field names 254 #[allow(non_camel_case_types)] 255 pub mod members { 256 ///Marker type for the `owner` field 257 pub struct owner(()); 258 ///Marker type for the `identifier` field 259 pub struct identifier(()); 260 } 261} 262 263/// Builder for constructing an instance of this type. 264pub struct DidRecordBuilder<S: BosStr, St: did_record_state::State> { 265 _state: PhantomData<fn() -> St>, 266 _fields: ( 267 Option<did::Did<S>>, 268 Option<S>, 269 Option<jacquard_common::types::string::Did<S>>, 270 ), 271 _type: PhantomData<fn() -> S>, 272} 273 274impl<S: BosStr> DidRecord<S> { 275 /// Create a new builder for this type. 276 pub fn new() -> DidRecordBuilder<S, did_record_state::Empty> { 277 DidRecordBuilder::new() 278 } 279} 280 281impl<S: BosStr> DidRecordBuilder<S, did_record_state::Empty> { 282 /// Create a new builder with all fields unset. 283 pub fn new() -> Self { 284 DidRecordBuilder { 285 _state: PhantomData, 286 _fields: (None, None, None), 287 _type: PhantomData, 288 } 289 } 290} 291 292impl<S: BosStr, St> DidRecordBuilder<S, St> 293where 294 St: did_record_state::State, 295 St::Identifier: did_record_state::IsUnset, 296{ 297 /// Set the `identifier` field (required) 298 pub fn identifier( 299 mut self, 300 value: impl Into<did::Did<S>>, 301 ) -> DidRecordBuilder<S, did_record_state::SetIdentifier<St>> { 302 self._fields.0 = Option::Some(value.into()); 303 DidRecordBuilder { 304 _state: PhantomData, 305 _fields: self._fields, 306 _type: PhantomData, 307 } 308 } 309} 310 311impl<S: BosStr, St: did_record_state::State> DidRecordBuilder<S, St> { 312 /// Set the `label` field (optional) 313 pub fn label(mut self, value: impl Into<Option<S>>) -> Self { 314 self._fields.1 = value.into(); 315 self 316 } 317 /// Set the `label` field to an Option value (optional) 318 pub fn maybe_label(mut self, value: Option<S>) -> Self { 319 self._fields.1 = value; 320 self 321 } 322} 323 324impl<S: BosStr, St> DidRecordBuilder<S, St> 325where 326 St: did_record_state::State, 327 St::Owner: did_record_state::IsUnset, 328{ 329 /// Set the `owner` field (required) 330 pub fn owner( 331 mut self, 332 value: impl Into<jacquard_common::types::string::Did<S>>, 333 ) -> DidRecordBuilder<S, did_record_state::SetOwner<St>> { 334 self._fields.2 = Option::Some(value.into()); 335 DidRecordBuilder { 336 _state: PhantomData, 337 _fields: self._fields, 338 _type: PhantomData, 339 } 340 } 341} 342 343impl<S: BosStr, St> DidRecordBuilder<S, St> 344where 345 St: did_record_state::State, 346 St::Owner: did_record_state::IsSet, 347 St::Identifier: did_record_state::IsSet, 348{ 349 /// Build the final struct. 350 pub fn build(self) -> DidRecord<S> { 351 DidRecord { 352 identifier: self._fields.0.unwrap(), 353 label: self._fields.1, 354 owner: self._fields.2.unwrap(), 355 extra_data: Default::default(), 356 } 357 } 358 /// Build the final struct with custom extra_data. 359 pub fn build_with_data( 360 self, 361 extra_data: BTreeMap<SmolStr, Data<S>>, 362 ) -> DidRecord<S> { 363 DidRecord { 364 identifier: self._fields.0.unwrap(), 365 label: self._fields.1, 366 owner: self._fields.2.unwrap(), 367 extra_data: Some(extra_data), 368 } 369 } 370}