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