A better Rust ATProto crate
1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: test.collision.collection
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 Collection that collides with the trait 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 Collection<S: jacquard_common::BosStr = jacquard_common::DefaultStr> {
26 #[serde(skip_serializing_if = "core::option::Option::is_none")]
27 pub count: core::option::Option<i64>,
28 pub label: S,
29 #[serde(flatten, default, skip_serializing_if = "core::option::Option::is_none")]
30 pub extra_data: core::option::Option<
31 alloc::collections::BTreeMap<
32 jacquard_common::deps::smol_str::SmolStr,
33 jacquard_common::types::value::Data<S>,
34 >,
35 >,
36}
37
38/// A record that itself references the Collection trait via its NSID.
39
40#[derive(
41 serde::Serialize,
42 serde::Deserialize,
43 Debug,
44 Clone,
45 PartialEq,
46 Eq,
47 jacquard_derive::IntoStatic
48)]
49
50#[serde(
51 rename_all = "camelCase",
52 rename = "test.collision.collection",
53 tag = "$type",
54 bound(deserialize = "S: serde::Deserialize<'de> + jacquard_common::BosStr")
55)]
56pub struct CollectionRecord<S: jacquard_common::BosStr = jacquard_common::DefaultStr> {
57 #[serde(skip_serializing_if = "core::option::Option::is_none")]
58 pub created_at: core::option::Option<jacquard_common::types::string::Datetime>,
59 pub items: Vec<crate::macro_mode::test_collision::collection::Collection<S>>,
60 pub name: 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
70/// Typed wrapper for GetRecord response with this collection's record type.
71
72#[derive(
73 serde::Serialize,
74 serde::Deserialize,
75 Debug,
76 Clone,
77 PartialEq,
78 Eq,
79 jacquard_derive::IntoStatic
80)]
81
82#[serde(rename_all = "camelCase")]
83pub struct CollectionRecordGetRecordOutput<
84 S: jacquard_common::BosStr = jacquard_common::DefaultStr,
85> {
86 #[serde(skip_serializing_if = "core::option::Option::is_none")]
87 pub cid: core::option::Option<jacquard_common::types::string::Cid<S>>,
88 pub uri: jacquard_common::types::string::AtUri<S>,
89 pub value: CollectionRecord<S>,
90}
91
92impl<S: jacquard_common::BosStr> CollectionRecord<S> {
93 pub fn uri(
94 uri: S,
95 ) -> Result<
96 jacquard_common::types::uri::RecordUri<S, CollectionRecordRecord>,
97 jacquard_common::types::uri::UriError,
98 > {
99 jacquard_common::types::uri::RecordUri::try_from_uri(
100 jacquard_common::types::string::AtUri::new(uri)?,
101 )
102 }
103}
104
105impl<S: jacquard_common::BosStr> jacquard_lexicon::schema::LexiconSchema
106for Collection<S> {
107 fn nsid() -> &'static str {
108 "test.collision.collection"
109 }
110 fn def_name() -> &'static str {
111 "collection"
112 }
113 fn lexicon_doc() -> jacquard_lexicon::lexicon::LexiconDoc<'static> {
114 lexicon_doc_test_collision_collection()
115 }
116 fn validate(&self) -> Result<(), jacquard_lexicon::validation::ConstraintError> {
117 if let Some(ref value) = self.count {
118 if *value < 0i64 {
119 return Err(jacquard_lexicon::validation::ConstraintError::Minimum {
120 path: jacquard_lexicon::validation::ValidationPath::from_field(
121 "count",
122 ),
123 min: 0i64,
124 actual: *value,
125 });
126 }
127 }
128 {
129 let value = &self.label;
130 #[allow(unused_comparisons)]
131 if <str>::len(value.as_ref()) > 100usize {
132 return Err(jacquard_lexicon::validation::ConstraintError::MaxLength {
133 path: jacquard_lexicon::validation::ValidationPath::from_field(
134 "label",
135 ),
136 max: 100usize,
137 actual: <str>::len(value.as_ref()),
138 });
139 }
140 }
141 Ok(())
142 }
143}
144
145/// Marker type for deserializing records from this collection.
146
147#[derive(Debug, serde::Serialize, serde::Deserialize)]
148pub struct CollectionRecordRecord;
149impl jacquard_common::xrpc::XrpcResp for CollectionRecordRecord {
150 const NSID: &'static str = "test.collision.collection";
151 const ENCODING: &'static str = "application/json";
152 type Output<S: jacquard_common::BosStr> = CollectionRecordGetRecordOutput<S>;
153 type Err = jacquard_common::types::collection::RecordError;
154}
155
156impl<S: jacquard_common::BosStr> From<CollectionRecordGetRecordOutput<S>>
157for CollectionRecord<S> {
158 fn from(output: CollectionRecordGetRecordOutput<S>) -> Self {
159 output.value
160 }
161}
162
163impl<S: jacquard_common::BosStr> jacquard_common::types::collection::Collection
164for CollectionRecord<S> {
165 const NSID: &'static str = "test.collision.collection";
166 type Record = CollectionRecordRecord;
167}
168
169impl jacquard_common::types::collection::Collection for CollectionRecordRecord {
170 const NSID: &'static str = "test.collision.collection";
171 type Record = CollectionRecordRecord;
172}
173
174impl<S: jacquard_common::BosStr> jacquard_lexicon::schema::LexiconSchema
175for CollectionRecord<S> {
176 fn nsid() -> &'static str {
177 "test.collision.collection"
178 }
179 fn def_name() -> &'static str {
180 "main"
181 }
182 fn lexicon_doc() -> jacquard_lexicon::lexicon::LexiconDoc<'static> {
183 lexicon_doc_test_collision_collection()
184 }
185 fn validate(&self) -> Result<(), jacquard_lexicon::validation::ConstraintError> {
186 {
187 let value = &self.name;
188 #[allow(unused_comparisons)]
189 if <str>::len(value.as_ref()) > 256usize {
190 return Err(jacquard_lexicon::validation::ConstraintError::MaxLength {
191 path: jacquard_lexicon::validation::ValidationPath::from_field(
192 "name",
193 ),
194 max: 256usize,
195 actual: <str>::len(value.as_ref()),
196 });
197 }
198 }
199 Ok(())
200 }
201}
202
203fn lexicon_doc_test_collision_collection() -> jacquard_lexicon::lexicon::LexiconDoc<
204 'static,
205> {
206 ::jacquard_lexicon::lexicon::LexiconDoc {
207 lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
208 id: ::jacquard_common::CowStr::new_static("test.collision.collection"),
209 defs: {
210 let mut map = ::alloc::collections::BTreeMap::new();
211 map.insert(
212 ::jacquard_common::deps::smol_str::SmolStr::new_static("collection"),
213 ::jacquard_lexicon::lexicon::LexUserType::Object(::jacquard_lexicon::lexicon::LexObject {
214 description: Some(
215 ::jacquard_common::CowStr::new_static(
216 "A locally-defined type named Collection that collides with the trait import.",
217 ),
218 ),
219 required: Some(
220 vec![
221 ::jacquard_common::deps::smol_str::SmolStr::new_static("label")
222 ],
223 ),
224 properties: {
225 #[allow(unused_mut)]
226 let mut map = ::alloc::collections::BTreeMap::new();
227 map.insert(
228 ::jacquard_common::deps::smol_str::SmolStr::new_static(
229 "count",
230 ),
231 ::jacquard_lexicon::lexicon::LexObjectProperty::Integer(::jacquard_lexicon::lexicon::LexInteger {
232 minimum: Some(0i64),
233 ..Default::default()
234 }),
235 );
236 map.insert(
237 ::jacquard_common::deps::smol_str::SmolStr::new_static(
238 "label",
239 ),
240 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
241 max_length: Some(100usize),
242 ..Default::default()
243 }),
244 );
245 map
246 },
247 ..Default::default()
248 }),
249 );
250 map.insert(
251 ::jacquard_common::deps::smol_str::SmolStr::new_static("main"),
252 ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord {
253 description: Some(
254 ::jacquard_common::CowStr::new_static(
255 "A record that itself references the Collection trait via its NSID.",
256 ),
257 ),
258 key: Some(::jacquard_common::CowStr::new_static("tid")),
259 record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject {
260 required: Some(
261 vec![
262 ::jacquard_common::deps::smol_str::SmolStr::new_static("name"),
263 ::jacquard_common::deps::smol_str::SmolStr::new_static("items")
264 ],
265 ),
266 properties: {
267 #[allow(unused_mut)]
268 let mut map = ::alloc::collections::BTreeMap::new();
269 map.insert(
270 ::jacquard_common::deps::smol_str::SmolStr::new_static(
271 "createdAt",
272 ),
273 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
274 format: Some(
275 ::jacquard_lexicon::lexicon::LexStringFormat::Datetime,
276 ),
277 ..Default::default()
278 }),
279 );
280 map.insert(
281 ::jacquard_common::deps::smol_str::SmolStr::new_static(
282 "items",
283 ),
284 ::jacquard_lexicon::lexicon::LexObjectProperty::Array(::jacquard_lexicon::lexicon::LexArray {
285 items: ::jacquard_lexicon::lexicon::LexArrayItem::Ref(::jacquard_lexicon::lexicon::LexRef {
286 r#ref: ::jacquard_common::CowStr::new_static("#collection"),
287 ..Default::default()
288 }),
289 ..Default::default()
290 }),
291 );
292 map.insert(
293 ::jacquard_common::deps::smol_str::SmolStr::new_static(
294 "name",
295 ),
296 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
297 max_length: Some(256usize),
298 ..Default::default()
299 }),
300 );
301 map
302 },
303 ..Default::default()
304 }),
305 ..Default::default()
306 }),
307 );
308 map
309 },
310 ..Default::default()
311 }
312}
313
314pub mod collection_record_state {
315
316 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
317 #[allow(unused)]
318 use ::core::marker::PhantomData;
319 mod sealed {
320 pub trait Sealed {}
321 }
322 /// State trait tracking which required fields have been set
323 pub trait State: sealed::Sealed {
324 type Items;
325 type Name;
326 }
327 /// Empty state - all required fields are unset
328 pub struct Empty(());
329 impl sealed::Sealed for Empty {}
330 impl State for Empty {
331 type Items = Unset;
332 type Name = Unset;
333 }
334 ///State transition - sets the `items` field to Set
335 pub struct SetItems<St: State = Empty>(PhantomData<fn() -> St>);
336 impl<St: State> sealed::Sealed for SetItems<St> {}
337 impl<St: State> State for SetItems<St> {
338 type Items = Set<members::items>;
339 type Name = St::Name;
340 }
341 ///State transition - sets the `name` field to Set
342 pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
343 impl<St: State> sealed::Sealed for SetName<St> {}
344 impl<St: State> State for SetName<St> {
345 type Items = St::Items;
346 type Name = Set<members::name>;
347 }
348 /// Marker types for field names
349 #[allow(non_camel_case_types)]
350 pub mod members {
351 ///Marker type for the `items` field
352 pub struct items(());
353 ///Marker type for the `name` field
354 pub struct name(());
355 }
356}
357
358/// Builder for constructing an instance of this type.
359pub struct CollectionRecordBuilder<
360 S: jacquard_common::BosStr,
361 St: collection_record_state::State,
362> {
363 _state: ::core::marker::PhantomData<fn() -> St>,
364 _fields: (
365 core::option::Option<jacquard_common::types::string::Datetime>,
366 core::option::Option<
367 Vec<crate::macro_mode::test_collision::collection::Collection<S>>,
368 >,
369 core::option::Option<S>,
370 ),
371 _type: ::core::marker::PhantomData<fn() -> S>,
372}
373
374impl<S: jacquard_common::BosStr> CollectionRecord<S> {
375 /// Create a new builder for this type.
376 pub fn new() -> CollectionRecordBuilder<S, collection_record_state::Empty> {
377 CollectionRecordBuilder::new()
378 }
379}
380
381impl<
382 S: jacquard_common::BosStr,
383> CollectionRecordBuilder<S, collection_record_state::Empty> {
384 /// Create a new builder with all fields unset.
385 pub fn new() -> Self {
386 CollectionRecordBuilder {
387 _state: ::core::marker::PhantomData,
388 _fields: (None, None, None),
389 _type: ::core::marker::PhantomData,
390 }
391 }
392}
393
394impl<
395 S: jacquard_common::BosStr,
396 St: collection_record_state::State,
397> CollectionRecordBuilder<S, St> {
398 /// Set the `createdAt` field (optional)
399 pub fn created_at(
400 mut self,
401 value: impl Into<Option<jacquard_common::types::string::Datetime>>,
402 ) -> Self {
403 self._fields.0 = value.into();
404 self
405 }
406 /// Set the `createdAt` field to an Option value (optional)
407 pub fn maybe_created_at(
408 mut self,
409 value: Option<jacquard_common::types::string::Datetime>,
410 ) -> Self {
411 self._fields.0 = value;
412 self
413 }
414}
415
416impl<S: jacquard_common::BosStr, St> CollectionRecordBuilder<S, St>
417where
418 St: collection_record_state::State,
419 St::Items: collection_record_state::IsUnset,
420{
421 /// Set the `items` field (required)
422 pub fn items(
423 mut self,
424 value: impl Into<
425 Vec<crate::macro_mode::test_collision::collection::Collection<S>>,
426 >,
427 ) -> CollectionRecordBuilder<S, collection_record_state::SetItems<St>> {
428 self._fields.1 = ::core::option::Option::Some(value.into());
429 CollectionRecordBuilder {
430 _state: ::core::marker::PhantomData,
431 _fields: self._fields,
432 _type: ::core::marker::PhantomData,
433 }
434 }
435}
436
437impl<S: jacquard_common::BosStr, St> CollectionRecordBuilder<S, St>
438where
439 St: collection_record_state::State,
440 St::Name: collection_record_state::IsUnset,
441{
442 /// Set the `name` field (required)
443 pub fn name(
444 mut self,
445 value: impl Into<S>,
446 ) -> CollectionRecordBuilder<S, collection_record_state::SetName<St>> {
447 self._fields.2 = ::core::option::Option::Some(value.into());
448 CollectionRecordBuilder {
449 _state: ::core::marker::PhantomData,
450 _fields: self._fields,
451 _type: ::core::marker::PhantomData,
452 }
453 }
454}
455
456impl<S: jacquard_common::BosStr, St> CollectionRecordBuilder<S, St>
457where
458 St: collection_record_state::State,
459 St::Items: collection_record_state::IsSet,
460 St::Name: collection_record_state::IsSet,
461{
462 /// Build the final struct.
463 pub fn build(self) -> CollectionRecord<S> {
464 CollectionRecord {
465 created_at: self._fields.0,
466 items: self._fields.1.unwrap(),
467 name: self._fields.2.unwrap(),
468 extra_data: Default::default(),
469 }
470 }
471 /// Build the final struct with custom extra_data.
472 pub fn build_with_data(
473 self,
474 extra_data: alloc::collections::BTreeMap<
475 jacquard_common::deps::smol_str::SmolStr,
476 jacquard_common::types::value::Data<S>,
477 >,
478 ) -> CollectionRecord<S> {
479 CollectionRecord {
480 created_at: self._fields.0,
481 items: self._fields.1.unwrap(),
482 name: self._fields.2.unwrap(),
483 extra_data: Some(extra_data),
484 }
485 }
486}