jacquard_api/blog_pckt/block/
iframe.rs1#[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")]
31 pub height: Option<i64>,
32 #[serde(borrow)]
34 pub url: UriValue<'a>,
35}
36
37impl<'a> LexiconSchema for Iframe<'a> {
38 fn nsid() -> &'static str {
39 "blog.pckt.block.iframe"
40 }
41 fn def_name() -> &'static str {
42 "main"
43 }
44 fn lexicon_doc() -> LexiconDoc<'static> {
45 lexicon_doc_blog_pckt_block_iframe()
46 }
47 fn validate(&self) -> Result<(), ConstraintError> {
48 if let Some(ref value) = self.height {
49 if *value > 1600i64 {
50 return Err(ConstraintError::Maximum {
51 path: ValidationPath::from_field("height"),
52 max: 1600i64,
53 actual: *value,
54 });
55 }
56 }
57 if let Some(ref value) = self.height {
58 if *value < 16i64 {
59 return Err(ConstraintError::Minimum {
60 path: ValidationPath::from_field("height"),
61 min: 16i64,
62 actual: *value,
63 });
64 }
65 }
66 Ok(())
67 }
68}
69
70pub mod iframe_state {
71
72 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
73 #[allow(unused)]
74 use ::core::marker::PhantomData;
75 mod sealed {
76 pub trait Sealed {}
77 }
78 pub trait State: sealed::Sealed {
80 type Url;
81 }
82 pub struct Empty(());
84 impl sealed::Sealed for Empty {}
85 impl State for Empty {
86 type Url = Unset;
87 }
88 pub struct SetUrl<S: State = Empty>(PhantomData<fn() -> S>);
90 impl<S: State> sealed::Sealed for SetUrl<S> {}
91 impl<S: State> State for SetUrl<S> {
92 type Url = Set<members::url>;
93 }
94 #[allow(non_camel_case_types)]
96 pub mod members {
97 pub struct url(());
99 }
100}
101
102pub struct IframeBuilder<'a, S: iframe_state::State> {
104 _state: PhantomData<fn() -> S>,
105 _fields: (Option<i64>, Option<UriValue<'a>>),
106 _lifetime: PhantomData<&'a ()>,
107}
108
109impl<'a> Iframe<'a> {
110 pub fn new() -> IframeBuilder<'a, iframe_state::Empty> {
112 IframeBuilder::new()
113 }
114}
115
116impl<'a> IframeBuilder<'a, iframe_state::Empty> {
117 pub fn new() -> Self {
119 IframeBuilder {
120 _state: PhantomData,
121 _fields: (None, None),
122 _lifetime: PhantomData,
123 }
124 }
125}
126
127impl<'a, S: iframe_state::State> IframeBuilder<'a, S> {
128 pub fn height(mut self, value: impl Into<Option<i64>>) -> Self {
130 self._fields.0 = value.into();
131 self
132 }
133 pub fn maybe_height(mut self, value: Option<i64>) -> Self {
135 self._fields.0 = value;
136 self
137 }
138}
139
140impl<'a, S> IframeBuilder<'a, S>
141where
142 S: iframe_state::State,
143 S::Url: iframe_state::IsUnset,
144{
145 pub fn url(
147 mut self,
148 value: impl Into<UriValue<'a>>,
149 ) -> IframeBuilder<'a, iframe_state::SetUrl<S>> {
150 self._fields.1 = Option::Some(value.into());
151 IframeBuilder {
152 _state: PhantomData,
153 _fields: self._fields,
154 _lifetime: PhantomData,
155 }
156 }
157}
158
159impl<'a, S> IframeBuilder<'a, S>
160where
161 S: iframe_state::State,
162 S::Url: iframe_state::IsSet,
163{
164 pub fn build(self) -> Iframe<'a> {
166 Iframe {
167 height: self._fields.0,
168 url: self._fields.1.unwrap(),
169 extra_data: Default::default(),
170 }
171 }
172 pub fn build_with_data(
174 self,
175 extra_data: BTreeMap<
176 jacquard_common::deps::smol_str::SmolStr,
177 jacquard_common::types::value::Data<'a>,
178 >,
179 ) -> Iframe<'a> {
180 Iframe {
181 height: self._fields.0,
182 url: self._fields.1.unwrap(),
183 extra_data: Some(extra_data),
184 }
185 }
186}
187
188fn lexicon_doc_blog_pckt_block_iframe() -> LexiconDoc<'static> {
189 #[allow(unused_imports)]
190 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
191 use jacquard_lexicon::lexicon::*;
192 use alloc::collections::BTreeMap;
193 LexiconDoc {
194 lexicon: Lexicon::Lexicon1,
195 id: CowStr::new_static("blog.pckt.block.iframe"),
196 defs: {
197 let mut map = BTreeMap::new();
198 map.insert(
199 SmolStr::new_static("main"),
200 LexUserType::Object(LexObject {
201 required: Some(vec![SmolStr::new_static("url")]),
202 properties: {
203 #[allow(unused_mut)]
204 let mut map = BTreeMap::new();
205 map.insert(
206 SmolStr::new_static("height"),
207 LexObjectProperty::Integer(LexInteger {
208 minimum: Some(16i64),
209 maximum: Some(1600i64),
210 ..Default::default()
211 }),
212 );
213 map.insert(
214 SmolStr::new_static("url"),
215 LexObjectProperty::String(LexString {
216 description: Some(
217 CowStr::new_static("The URL of the content to embed"),
218 ),
219 format: Some(LexStringFormat::Uri),
220 ..Default::default()
221 }),
222 );
223 map
224 },
225 ..Default::default()
226 }),
227 );
228 map
229 },
230 ..Default::default()
231 }
232}