Skip to main content

jacquard_api/network_slices/
tools.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: network.slices.tools.defs
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8pub mod bug;
9pub mod document;
10pub mod richtext;
11
12
13#[allow(unused_imports)]
14use alloc::collections::BTreeMap;
15
16#[allow(unused_imports)]
17use core::marker::PhantomData;
18use jacquard_common::CowStr;
19
20#[allow(unused_imports)]
21use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
22use jacquard_common::types::blob::BlobRef;
23use jacquard_derive::{IntoStatic, lexicon};
24use jacquard_lexicon::lexicon::LexiconDoc;
25use jacquard_lexicon::schema::LexiconSchema;
26
27#[allow(unused_imports)]
28use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
29use serde::{Serialize, Deserialize};
30use crate::network_slices::tools;
31
32#[lexicon]
33#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
34#[serde(rename_all = "camelCase")]
35pub struct Image<'a> {
36    ///Alt text description of the image, for accessibility
37    #[serde(borrow)]
38    pub alt: CowStr<'a>,
39    #[serde(borrow)]
40    pub image: BlobRef<'a>,
41}
42
43
44#[lexicon]
45#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
46#[serde(rename_all = "camelCase")]
47pub struct Images<'a> {
48    #[serde(borrow)]
49    pub images: Vec<tools::Image<'a>>,
50}
51
52impl<'a> LexiconSchema for Image<'a> {
53    fn nsid() -> &'static str {
54        "network.slices.tools.defs"
55    }
56    fn def_name() -> &'static str {
57        "image"
58    }
59    fn lexicon_doc() -> LexiconDoc<'static> {
60        lexicon_doc_network_slices_tools_defs()
61    }
62    fn validate(&self) -> Result<(), ConstraintError> {
63        {
64            let value = &self.image;
65            {
66                let size = value.blob().size;
67                if size > 1000000usize {
68                    return Err(ConstraintError::BlobTooLarge {
69                        path: ValidationPath::from_field("image"),
70                        max: 1000000usize,
71                        actual: size,
72                    });
73                }
74            }
75        }
76        {
77            let value = &self.image;
78            {
79                let mime = value.blob().mime_type.as_str();
80                let accepted: &[&str] = &["image/*"];
81                let matched = accepted
82                    .iter()
83                    .any(|pattern| {
84                        if *pattern == "*/*" {
85                            true
86                        } else if pattern.ends_with("/*") {
87                            let prefix = &pattern[..pattern.len() - 2];
88                            mime.starts_with(prefix)
89                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
90                        } else {
91                            mime == *pattern
92                        }
93                    });
94                if !matched {
95                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
96                        path: ValidationPath::from_field("image"),
97                        accepted: vec!["image/*".to_string()],
98                        actual: mime.to_string(),
99                    });
100                }
101            }
102        }
103        Ok(())
104    }
105}
106
107impl<'a> LexiconSchema for Images<'a> {
108    fn nsid() -> &'static str {
109        "network.slices.tools.defs"
110    }
111    fn def_name() -> &'static str {
112        "images"
113    }
114    fn lexicon_doc() -> LexiconDoc<'static> {
115        lexicon_doc_network_slices_tools_defs()
116    }
117    fn validate(&self) -> Result<(), ConstraintError> {
118        {
119            let value = &self.images;
120            #[allow(unused_comparisons)]
121            if value.len() > 4usize {
122                return Err(ConstraintError::MaxLength {
123                    path: ValidationPath::from_field("images"),
124                    max: 4usize,
125                    actual: value.len(),
126                });
127            }
128        }
129        Ok(())
130    }
131}
132
133pub mod image_state {
134
135    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
136    #[allow(unused)]
137    use ::core::marker::PhantomData;
138    mod sealed {
139        pub trait Sealed {}
140    }
141    /// State trait tracking which required fields have been set
142    pub trait State: sealed::Sealed {
143        type Image;
144        type Alt;
145    }
146    /// Empty state - all required fields are unset
147    pub struct Empty(());
148    impl sealed::Sealed for Empty {}
149    impl State for Empty {
150        type Image = Unset;
151        type Alt = Unset;
152    }
153    ///State transition - sets the `image` field to Set
154    pub struct SetImage<S: State = Empty>(PhantomData<fn() -> S>);
155    impl<S: State> sealed::Sealed for SetImage<S> {}
156    impl<S: State> State for SetImage<S> {
157        type Image = Set<members::image>;
158        type Alt = S::Alt;
159    }
160    ///State transition - sets the `alt` field to Set
161    pub struct SetAlt<S: State = Empty>(PhantomData<fn() -> S>);
162    impl<S: State> sealed::Sealed for SetAlt<S> {}
163    impl<S: State> State for SetAlt<S> {
164        type Image = S::Image;
165        type Alt = Set<members::alt>;
166    }
167    /// Marker types for field names
168    #[allow(non_camel_case_types)]
169    pub mod members {
170        ///Marker type for the `image` field
171        pub struct image(());
172        ///Marker type for the `alt` field
173        pub struct alt(());
174    }
175}
176
177/// Builder for constructing an instance of this type
178pub struct ImageBuilder<'a, S: image_state::State> {
179    _state: PhantomData<fn() -> S>,
180    _fields: (Option<CowStr<'a>>, Option<BlobRef<'a>>),
181    _lifetime: PhantomData<&'a ()>,
182}
183
184impl<'a> Image<'a> {
185    /// Create a new builder for this type
186    pub fn new() -> ImageBuilder<'a, image_state::Empty> {
187        ImageBuilder::new()
188    }
189}
190
191impl<'a> ImageBuilder<'a, image_state::Empty> {
192    /// Create a new builder with all fields unset
193    pub fn new() -> Self {
194        ImageBuilder {
195            _state: PhantomData,
196            _fields: (None, None),
197            _lifetime: PhantomData,
198        }
199    }
200}
201
202impl<'a, S> ImageBuilder<'a, S>
203where
204    S: image_state::State,
205    S::Alt: image_state::IsUnset,
206{
207    /// Set the `alt` field (required)
208    pub fn alt(
209        mut self,
210        value: impl Into<CowStr<'a>>,
211    ) -> ImageBuilder<'a, image_state::SetAlt<S>> {
212        self._fields.0 = Option::Some(value.into());
213        ImageBuilder {
214            _state: PhantomData,
215            _fields: self._fields,
216            _lifetime: PhantomData,
217        }
218    }
219}
220
221impl<'a, S> ImageBuilder<'a, S>
222where
223    S: image_state::State,
224    S::Image: image_state::IsUnset,
225{
226    /// Set the `image` field (required)
227    pub fn image(
228        mut self,
229        value: impl Into<BlobRef<'a>>,
230    ) -> ImageBuilder<'a, image_state::SetImage<S>> {
231        self._fields.1 = Option::Some(value.into());
232        ImageBuilder {
233            _state: PhantomData,
234            _fields: self._fields,
235            _lifetime: PhantomData,
236        }
237    }
238}
239
240impl<'a, S> ImageBuilder<'a, S>
241where
242    S: image_state::State,
243    S::Image: image_state::IsSet,
244    S::Alt: image_state::IsSet,
245{
246    /// Build the final struct
247    pub fn build(self) -> Image<'a> {
248        Image {
249            alt: self._fields.0.unwrap(),
250            image: self._fields.1.unwrap(),
251            extra_data: Default::default(),
252        }
253    }
254    /// Build the final struct with custom extra_data
255    pub fn build_with_data(
256        self,
257        extra_data: BTreeMap<
258            jacquard_common::deps::smol_str::SmolStr,
259            jacquard_common::types::value::Data<'a>,
260        >,
261    ) -> Image<'a> {
262        Image {
263            alt: self._fields.0.unwrap(),
264            image: self._fields.1.unwrap(),
265            extra_data: Some(extra_data),
266        }
267    }
268}
269
270fn lexicon_doc_network_slices_tools_defs() -> LexiconDoc<'static> {
271    #[allow(unused_imports)]
272    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
273    use jacquard_lexicon::lexicon::*;
274    use alloc::collections::BTreeMap;
275    LexiconDoc {
276        lexicon: Lexicon::Lexicon1,
277        id: CowStr::new_static("network.slices.tools.defs"),
278        defs: {
279            let mut map = BTreeMap::new();
280            map.insert(
281                SmolStr::new_static("image"),
282                LexUserType::Object(LexObject {
283                    required: Some(
284                        vec![SmolStr::new_static("image"), SmolStr::new_static("alt")],
285                    ),
286                    properties: {
287                        #[allow(unused_mut)]
288                        let mut map = BTreeMap::new();
289                        map.insert(
290                            SmolStr::new_static("alt"),
291                            LexObjectProperty::String(LexString {
292                                description: Some(
293                                    CowStr::new_static(
294                                        "Alt text description of the image, for accessibility",
295                                    ),
296                                ),
297                                ..Default::default()
298                            }),
299                        );
300                        map.insert(
301                            SmolStr::new_static("image"),
302                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
303                        );
304                        map
305                    },
306                    ..Default::default()
307                }),
308            );
309            map.insert(
310                SmolStr::new_static("images"),
311                LexUserType::Object(LexObject {
312                    required: Some(vec![SmolStr::new_static("images")]),
313                    properties: {
314                        #[allow(unused_mut)]
315                        let mut map = BTreeMap::new();
316                        map.insert(
317                            SmolStr::new_static("images"),
318                            LexObjectProperty::Array(LexArray {
319                                items: LexArrayItem::Ref(LexRef {
320                                    r#ref: CowStr::new_static("#image"),
321                                    ..Default::default()
322                                }),
323                                max_length: Some(4usize),
324                                ..Default::default()
325                            }),
326                        );
327                        map
328                    },
329                    ..Default::default()
330                }),
331            );
332            map
333        },
334        ..Default::default()
335    }
336}
337
338pub mod images_state {
339
340    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
341    #[allow(unused)]
342    use ::core::marker::PhantomData;
343    mod sealed {
344        pub trait Sealed {}
345    }
346    /// State trait tracking which required fields have been set
347    pub trait State: sealed::Sealed {
348        type Images;
349    }
350    /// Empty state - all required fields are unset
351    pub struct Empty(());
352    impl sealed::Sealed for Empty {}
353    impl State for Empty {
354        type Images = Unset;
355    }
356    ///State transition - sets the `images` field to Set
357    pub struct SetImages<S: State = Empty>(PhantomData<fn() -> S>);
358    impl<S: State> sealed::Sealed for SetImages<S> {}
359    impl<S: State> State for SetImages<S> {
360        type Images = Set<members::images>;
361    }
362    /// Marker types for field names
363    #[allow(non_camel_case_types)]
364    pub mod members {
365        ///Marker type for the `images` field
366        pub struct images(());
367    }
368}
369
370/// Builder for constructing an instance of this type
371pub struct ImagesBuilder<'a, S: images_state::State> {
372    _state: PhantomData<fn() -> S>,
373    _fields: (Option<Vec<tools::Image<'a>>>,),
374    _lifetime: PhantomData<&'a ()>,
375}
376
377impl<'a> Images<'a> {
378    /// Create a new builder for this type
379    pub fn new() -> ImagesBuilder<'a, images_state::Empty> {
380        ImagesBuilder::new()
381    }
382}
383
384impl<'a> ImagesBuilder<'a, images_state::Empty> {
385    /// Create a new builder with all fields unset
386    pub fn new() -> Self {
387        ImagesBuilder {
388            _state: PhantomData,
389            _fields: (None,),
390            _lifetime: PhantomData,
391        }
392    }
393}
394
395impl<'a, S> ImagesBuilder<'a, S>
396where
397    S: images_state::State,
398    S::Images: images_state::IsUnset,
399{
400    /// Set the `images` field (required)
401    pub fn images(
402        mut self,
403        value: impl Into<Vec<tools::Image<'a>>>,
404    ) -> ImagesBuilder<'a, images_state::SetImages<S>> {
405        self._fields.0 = Option::Some(value.into());
406        ImagesBuilder {
407            _state: PhantomData,
408            _fields: self._fields,
409            _lifetime: PhantomData,
410        }
411    }
412}
413
414impl<'a, S> ImagesBuilder<'a, S>
415where
416    S: images_state::State,
417    S::Images: images_state::IsSet,
418{
419    /// Build the final struct
420    pub fn build(self) -> Images<'a> {
421        Images {
422            images: self._fields.0.unwrap(),
423            extra_data: Default::default(),
424        }
425    }
426    /// Build the final struct with custom extra_data
427    pub fn build_with_data(
428        self,
429        extra_data: BTreeMap<
430            jacquard_common::deps::smol_str::SmolStr,
431            jacquard_common::types::value::Data<'a>,
432        >,
433    ) -> Images<'a> {
434        Images {
435            images: self._fields.0.unwrap(),
436            extra_data: Some(extra_data),
437        }
438    }
439}