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