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