Skip to main content

jacquard_api/network_slices/
actor.rs

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