jacquard_api/blog_pckt/block/
ordered_list.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_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::list_item::ListItem;
24
25#[lexicon]
26#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
27#[serde(rename_all = "camelCase")]
28pub struct OrderedList<'a> {
29 #[serde(borrow)]
31 pub content: Vec<ListItem<'a>>,
32 #[serde(skip_serializing_if = "Option::is_none")]
34 pub start: Option<i64>,
35}
36
37impl<'a> LexiconSchema for OrderedList<'a> {
38 fn nsid() -> &'static str {
39 "blog.pckt.block.orderedList"
40 }
41 fn def_name() -> &'static str {
42 "main"
43 }
44 fn lexicon_doc() -> LexiconDoc<'static> {
45 lexicon_doc_blog_pckt_block_orderedList()
46 }
47 fn validate(&self) -> Result<(), ConstraintError> {
48 if let Some(ref value) = self.start {
49 if *value < 1i64 {
50 return Err(ConstraintError::Minimum {
51 path: ValidationPath::from_field("start"),
52 min: 1i64,
53 actual: *value,
54 });
55 }
56 }
57 Ok(())
58 }
59}
60
61pub mod ordered_list_state {
62
63 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
64 #[allow(unused)]
65 use ::core::marker::PhantomData;
66 mod sealed {
67 pub trait Sealed {}
68 }
69 pub trait State: sealed::Sealed {
71 type Content;
72 }
73 pub struct Empty(());
75 impl sealed::Sealed for Empty {}
76 impl State for Empty {
77 type Content = Unset;
78 }
79 pub struct SetContent<S: State = Empty>(PhantomData<fn() -> S>);
81 impl<S: State> sealed::Sealed for SetContent<S> {}
82 impl<S: State> State for SetContent<S> {
83 type Content = Set<members::content>;
84 }
85 #[allow(non_camel_case_types)]
87 pub mod members {
88 pub struct content(());
90 }
91}
92
93pub struct OrderedListBuilder<'a, S: ordered_list_state::State> {
95 _state: PhantomData<fn() -> S>,
96 _fields: (Option<Vec<ListItem<'a>>>, Option<i64>),
97 _lifetime: PhantomData<&'a ()>,
98}
99
100impl<'a> OrderedList<'a> {
101 pub fn new() -> OrderedListBuilder<'a, ordered_list_state::Empty> {
103 OrderedListBuilder::new()
104 }
105}
106
107impl<'a> OrderedListBuilder<'a, ordered_list_state::Empty> {
108 pub fn new() -> Self {
110 OrderedListBuilder {
111 _state: PhantomData,
112 _fields: (None, None),
113 _lifetime: PhantomData,
114 }
115 }
116}
117
118impl<'a, S> OrderedListBuilder<'a, S>
119where
120 S: ordered_list_state::State,
121 S::Content: ordered_list_state::IsUnset,
122{
123 pub fn content(
125 mut self,
126 value: impl Into<Vec<ListItem<'a>>>,
127 ) -> OrderedListBuilder<'a, ordered_list_state::SetContent<S>> {
128 self._fields.0 = Option::Some(value.into());
129 OrderedListBuilder {
130 _state: PhantomData,
131 _fields: self._fields,
132 _lifetime: PhantomData,
133 }
134 }
135}
136
137impl<'a, S: ordered_list_state::State> OrderedListBuilder<'a, S> {
138 pub fn start(mut self, value: impl Into<Option<i64>>) -> Self {
140 self._fields.1 = value.into();
141 self
142 }
143 pub fn maybe_start(mut self, value: Option<i64>) -> Self {
145 self._fields.1 = value;
146 self
147 }
148}
149
150impl<'a, S> OrderedListBuilder<'a, S>
151where
152 S: ordered_list_state::State,
153 S::Content: ordered_list_state::IsSet,
154{
155 pub fn build(self) -> OrderedList<'a> {
157 OrderedList {
158 content: self._fields.0.unwrap(),
159 start: self._fields.1,
160 extra_data: Default::default(),
161 }
162 }
163 pub fn build_with_data(
165 self,
166 extra_data: BTreeMap<
167 jacquard_common::deps::smol_str::SmolStr,
168 jacquard_common::types::value::Data<'a>,
169 >,
170 ) -> OrderedList<'a> {
171 OrderedList {
172 content: self._fields.0.unwrap(),
173 start: self._fields.1,
174 extra_data: Some(extra_data),
175 }
176 }
177}
178
179fn lexicon_doc_blog_pckt_block_orderedList() -> LexiconDoc<'static> {
180 #[allow(unused_imports)]
181 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
182 use jacquard_lexicon::lexicon::*;
183 use alloc::collections::BTreeMap;
184 LexiconDoc {
185 lexicon: Lexicon::Lexicon1,
186 id: CowStr::new_static("blog.pckt.block.orderedList"),
187 defs: {
188 let mut map = BTreeMap::new();
189 map.insert(
190 SmolStr::new_static("main"),
191 LexUserType::Object(LexObject {
192 required: Some(vec![SmolStr::new_static("content")]),
193 properties: {
194 #[allow(unused_mut)]
195 let mut map = BTreeMap::new();
196 map.insert(
197 SmolStr::new_static("content"),
198 LexObjectProperty::Array(LexArray {
199 description: Some(
200 CowStr::new_static("Array of list items"),
201 ),
202 items: LexArrayItem::Ref(LexRef {
203 r#ref: CowStr::new_static("blog.pckt.block.listItem"),
204 ..Default::default()
205 }),
206 ..Default::default()
207 }),
208 );
209 map.insert(
210 SmolStr::new_static("start"),
211 LexObjectProperty::Integer(LexInteger {
212 minimum: Some(1i64),
213 ..Default::default()
214 }),
215 );
216 map
217 },
218 ..Default::default()
219 }),
220 );
221 map
222 },
223 ..Default::default()
224 }
225}