Skip to main content

jacquard_api/pub_leaflet/blocks/
iframe.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: pub.leaflet.blocks.iframe
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;
13
14#[allow(unused_imports)]
15use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
16use jacquard_common::types::string::UriValue;
17use jacquard_derive::{IntoStatic, lexicon};
18use jacquard_lexicon::lexicon::LexiconDoc;
19use jacquard_lexicon::schema::LexiconSchema;
20
21#[allow(unused_imports)]
22use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
23use serde::{Serialize, Deserialize};
24
25#[lexicon]
26#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
27#[serde(rename_all = "camelCase")]
28pub struct Iframe<'a> {
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub height: Option<i64>,
31    #[serde(borrow)]
32    pub url: UriValue<'a>,
33}
34
35impl<'a> LexiconSchema for Iframe<'a> {
36    fn nsid() -> &'static str {
37        "pub.leaflet.blocks.iframe"
38    }
39    fn def_name() -> &'static str {
40        "main"
41    }
42    fn lexicon_doc() -> LexiconDoc<'static> {
43        lexicon_doc_pub_leaflet_blocks_iframe()
44    }
45    fn validate(&self) -> Result<(), ConstraintError> {
46        if let Some(ref value) = self.height {
47            if *value > 1600i64 {
48                return Err(ConstraintError::Maximum {
49                    path: ValidationPath::from_field("height"),
50                    max: 1600i64,
51                    actual: *value,
52                });
53            }
54        }
55        if let Some(ref value) = self.height {
56            if *value < 16i64 {
57                return Err(ConstraintError::Minimum {
58                    path: ValidationPath::from_field("height"),
59                    min: 16i64,
60                    actual: *value,
61                });
62            }
63        }
64        Ok(())
65    }
66}
67
68pub mod iframe_state {
69
70    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
71    #[allow(unused)]
72    use ::core::marker::PhantomData;
73    mod sealed {
74        pub trait Sealed {}
75    }
76    /// State trait tracking which required fields have been set
77    pub trait State: sealed::Sealed {
78        type Url;
79    }
80    /// Empty state - all required fields are unset
81    pub struct Empty(());
82    impl sealed::Sealed for Empty {}
83    impl State for Empty {
84        type Url = Unset;
85    }
86    ///State transition - sets the `url` field to Set
87    pub struct SetUrl<S: State = Empty>(PhantomData<fn() -> S>);
88    impl<S: State> sealed::Sealed for SetUrl<S> {}
89    impl<S: State> State for SetUrl<S> {
90        type Url = Set<members::url>;
91    }
92    /// Marker types for field names
93    #[allow(non_camel_case_types)]
94    pub mod members {
95        ///Marker type for the `url` field
96        pub struct url(());
97    }
98}
99
100/// Builder for constructing an instance of this type
101pub struct IframeBuilder<'a, S: iframe_state::State> {
102    _state: PhantomData<fn() -> S>,
103    _fields: (Option<i64>, Option<UriValue<'a>>),
104    _lifetime: PhantomData<&'a ()>,
105}
106
107impl<'a> Iframe<'a> {
108    /// Create a new builder for this type
109    pub fn new() -> IframeBuilder<'a, iframe_state::Empty> {
110        IframeBuilder::new()
111    }
112}
113
114impl<'a> IframeBuilder<'a, iframe_state::Empty> {
115    /// Create a new builder with all fields unset
116    pub fn new() -> Self {
117        IframeBuilder {
118            _state: PhantomData,
119            _fields: (None, None),
120            _lifetime: PhantomData,
121        }
122    }
123}
124
125impl<'a, S: iframe_state::State> IframeBuilder<'a, S> {
126    /// Set the `height` field (optional)
127    pub fn height(mut self, value: impl Into<Option<i64>>) -> Self {
128        self._fields.0 = value.into();
129        self
130    }
131    /// Set the `height` field to an Option value (optional)
132    pub fn maybe_height(mut self, value: Option<i64>) -> Self {
133        self._fields.0 = value;
134        self
135    }
136}
137
138impl<'a, S> IframeBuilder<'a, S>
139where
140    S: iframe_state::State,
141    S::Url: iframe_state::IsUnset,
142{
143    /// Set the `url` field (required)
144    pub fn url(
145        mut self,
146        value: impl Into<UriValue<'a>>,
147    ) -> IframeBuilder<'a, iframe_state::SetUrl<S>> {
148        self._fields.1 = Option::Some(value.into());
149        IframeBuilder {
150            _state: PhantomData,
151            _fields: self._fields,
152            _lifetime: PhantomData,
153        }
154    }
155}
156
157impl<'a, S> IframeBuilder<'a, S>
158where
159    S: iframe_state::State,
160    S::Url: iframe_state::IsSet,
161{
162    /// Build the final struct
163    pub fn build(self) -> Iframe<'a> {
164        Iframe {
165            height: self._fields.0,
166            url: self._fields.1.unwrap(),
167            extra_data: Default::default(),
168        }
169    }
170    /// Build the final struct with custom extra_data
171    pub fn build_with_data(
172        self,
173        extra_data: BTreeMap<
174            jacquard_common::deps::smol_str::SmolStr,
175            jacquard_common::types::value::Data<'a>,
176        >,
177    ) -> Iframe<'a> {
178        Iframe {
179            height: self._fields.0,
180            url: self._fields.1.unwrap(),
181            extra_data: Some(extra_data),
182        }
183    }
184}
185
186fn lexicon_doc_pub_leaflet_blocks_iframe() -> LexiconDoc<'static> {
187    #[allow(unused_imports)]
188    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
189    use jacquard_lexicon::lexicon::*;
190    use alloc::collections::BTreeMap;
191    LexiconDoc {
192        lexicon: Lexicon::Lexicon1,
193        id: CowStr::new_static("pub.leaflet.blocks.iframe"),
194        defs: {
195            let mut map = BTreeMap::new();
196            map.insert(
197                SmolStr::new_static("main"),
198                LexUserType::Object(LexObject {
199                    required: Some(vec![SmolStr::new_static("url")]),
200                    properties: {
201                        #[allow(unused_mut)]
202                        let mut map = BTreeMap::new();
203                        map.insert(
204                            SmolStr::new_static("height"),
205                            LexObjectProperty::Integer(LexInteger {
206                                minimum: Some(16i64),
207                                maximum: Some(1600i64),
208                                ..Default::default()
209                            }),
210                        );
211                        map.insert(
212                            SmolStr::new_static("url"),
213                            LexObjectProperty::String(LexString {
214                                format: Some(LexStringFormat::Uri),
215                                ..Default::default()
216                            }),
217                        );
218                        map
219                    },
220                    ..Default::default()
221                }),
222            );
223            map
224        },
225        ..Default::default()
226    }
227}