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