Skip to main content

jacquard_api/blog_pckt/block/
table_header.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: blog.pckt.block.tableHeader
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_derive::{IntoStatic, lexicon};
17use jacquard_lexicon::lexicon::LexiconDoc;
18use jacquard_lexicon::schema::LexiconSchema;
19
20#[allow(unused_imports)]
21use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
22use serde::{Serialize, Deserialize};
23use crate::blog_pckt::block::text::Text;
24
25#[lexicon]
26#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
27#[serde(rename_all = "camelCase")]
28pub struct TableHeader<'a> {
29    ///Number of columns this cell spans
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub colspan: Option<i64>,
32    ///Array of block content (typically text)
33    #[serde(borrow)]
34    pub content: Vec<Text<'a>>,
35    ///Number of rows this cell spans
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub rowspan: Option<i64>,
38}
39
40impl<'a> LexiconSchema for TableHeader<'a> {
41    fn nsid() -> &'static str {
42        "blog.pckt.block.tableHeader"
43    }
44    fn def_name() -> &'static str {
45        "main"
46    }
47    fn lexicon_doc() -> LexiconDoc<'static> {
48        lexicon_doc_blog_pckt_block_tableHeader()
49    }
50    fn validate(&self) -> Result<(), ConstraintError> {
51        if let Some(ref value) = self.colspan {
52            if *value < 1i64 {
53                return Err(ConstraintError::Minimum {
54                    path: ValidationPath::from_field("colspan"),
55                    min: 1i64,
56                    actual: *value,
57                });
58            }
59        }
60        if let Some(ref value) = self.rowspan {
61            if *value < 1i64 {
62                return Err(ConstraintError::Minimum {
63                    path: ValidationPath::from_field("rowspan"),
64                    min: 1i64,
65                    actual: *value,
66                });
67            }
68        }
69        Ok(())
70    }
71}
72
73pub mod table_header_state {
74
75    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
76    #[allow(unused)]
77    use ::core::marker::PhantomData;
78    mod sealed {
79        pub trait Sealed {}
80    }
81    /// State trait tracking which required fields have been set
82    pub trait State: sealed::Sealed {
83        type Content;
84    }
85    /// Empty state - all required fields are unset
86    pub struct Empty(());
87    impl sealed::Sealed for Empty {}
88    impl State for Empty {
89        type Content = Unset;
90    }
91    ///State transition - sets the `content` field to Set
92    pub struct SetContent<S: State = Empty>(PhantomData<fn() -> S>);
93    impl<S: State> sealed::Sealed for SetContent<S> {}
94    impl<S: State> State for SetContent<S> {
95        type Content = Set<members::content>;
96    }
97    /// Marker types for field names
98    #[allow(non_camel_case_types)]
99    pub mod members {
100        ///Marker type for the `content` field
101        pub struct content(());
102    }
103}
104
105/// Builder for constructing an instance of this type
106pub struct TableHeaderBuilder<'a, S: table_header_state::State> {
107    _state: PhantomData<fn() -> S>,
108    _fields: (Option<i64>, Option<Vec<Text<'a>>>, Option<i64>),
109    _lifetime: PhantomData<&'a ()>,
110}
111
112impl<'a> TableHeader<'a> {
113    /// Create a new builder for this type
114    pub fn new() -> TableHeaderBuilder<'a, table_header_state::Empty> {
115        TableHeaderBuilder::new()
116    }
117}
118
119impl<'a> TableHeaderBuilder<'a, table_header_state::Empty> {
120    /// Create a new builder with all fields unset
121    pub fn new() -> Self {
122        TableHeaderBuilder {
123            _state: PhantomData,
124            _fields: (None, None, None),
125            _lifetime: PhantomData,
126        }
127    }
128}
129
130impl<'a, S: table_header_state::State> TableHeaderBuilder<'a, S> {
131    /// Set the `colspan` field (optional)
132    pub fn colspan(mut self, value: impl Into<Option<i64>>) -> Self {
133        self._fields.0 = value.into();
134        self
135    }
136    /// Set the `colspan` field to an Option value (optional)
137    pub fn maybe_colspan(mut self, value: Option<i64>) -> Self {
138        self._fields.0 = value;
139        self
140    }
141}
142
143impl<'a, S> TableHeaderBuilder<'a, S>
144where
145    S: table_header_state::State,
146    S::Content: table_header_state::IsUnset,
147{
148    /// Set the `content` field (required)
149    pub fn content(
150        mut self,
151        value: impl Into<Vec<Text<'a>>>,
152    ) -> TableHeaderBuilder<'a, table_header_state::SetContent<S>> {
153        self._fields.1 = Option::Some(value.into());
154        TableHeaderBuilder {
155            _state: PhantomData,
156            _fields: self._fields,
157            _lifetime: PhantomData,
158        }
159    }
160}
161
162impl<'a, S: table_header_state::State> TableHeaderBuilder<'a, S> {
163    /// Set the `rowspan` field (optional)
164    pub fn rowspan(mut self, value: impl Into<Option<i64>>) -> Self {
165        self._fields.2 = value.into();
166        self
167    }
168    /// Set the `rowspan` field to an Option value (optional)
169    pub fn maybe_rowspan(mut self, value: Option<i64>) -> Self {
170        self._fields.2 = value;
171        self
172    }
173}
174
175impl<'a, S> TableHeaderBuilder<'a, S>
176where
177    S: table_header_state::State,
178    S::Content: table_header_state::IsSet,
179{
180    /// Build the final struct
181    pub fn build(self) -> TableHeader<'a> {
182        TableHeader {
183            colspan: self._fields.0,
184            content: self._fields.1.unwrap(),
185            rowspan: self._fields.2,
186            extra_data: Default::default(),
187        }
188    }
189    /// Build the final struct with custom extra_data
190    pub fn build_with_data(
191        self,
192        extra_data: BTreeMap<
193            jacquard_common::deps::smol_str::SmolStr,
194            jacquard_common::types::value::Data<'a>,
195        >,
196    ) -> TableHeader<'a> {
197        TableHeader {
198            colspan: self._fields.0,
199            content: self._fields.1.unwrap(),
200            rowspan: self._fields.2,
201            extra_data: Some(extra_data),
202        }
203    }
204}
205
206fn lexicon_doc_blog_pckt_block_tableHeader() -> LexiconDoc<'static> {
207    #[allow(unused_imports)]
208    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
209    use jacquard_lexicon::lexicon::*;
210    use alloc::collections::BTreeMap;
211    LexiconDoc {
212        lexicon: Lexicon::Lexicon1,
213        id: CowStr::new_static("blog.pckt.block.tableHeader"),
214        defs: {
215            let mut map = BTreeMap::new();
216            map.insert(
217                SmolStr::new_static("main"),
218                LexUserType::Object(LexObject {
219                    required: Some(vec![SmolStr::new_static("content")]),
220                    properties: {
221                        #[allow(unused_mut)]
222                        let mut map = BTreeMap::new();
223                        map.insert(
224                            SmolStr::new_static("colspan"),
225                            LexObjectProperty::Integer(LexInteger {
226                                minimum: Some(1i64),
227                                ..Default::default()
228                            }),
229                        );
230                        map.insert(
231                            SmolStr::new_static("content"),
232                            LexObjectProperty::Array(LexArray {
233                                description: Some(
234                                    CowStr::new_static(
235                                        "Array of block content (typically text)",
236                                    ),
237                                ),
238                                items: LexArrayItem::Union(LexRefUnion {
239                                    refs: vec![CowStr::new_static("blog.pckt.block.text")],
240                                    closed: Some(false),
241                                    ..Default::default()
242                                }),
243                                ..Default::default()
244                            }),
245                        );
246                        map.insert(
247                            SmolStr::new_static("rowspan"),
248                            LexObjectProperty::Integer(LexInteger {
249                                minimum: Some(1i64),
250                                ..Default::default()
251                            }),
252                        );
253                        map
254                    },
255                    ..Default::default()
256                }),
257            );
258            map
259        },
260        ..Default::default()
261    }
262}