jacquard_api/pub_leaflet/
content.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, open_union};
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::pub_leaflet::pages::canvas::Canvas;
24use crate::pub_leaflet::pages::linear_document::LinearDocument;
25#[lexicon]
28#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
29#[serde(rename_all = "camelCase")]
30pub struct Content<'a> {
31 #[serde(borrow)]
32 pub pages: Vec<ContentPagesItem<'a>>,
33}
34
35
36#[open_union]
37#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
38#[serde(tag = "$type", bound(deserialize = "'de: 'a"))]
39pub enum ContentPagesItem<'a> {
40 #[serde(rename = "pub.leaflet.pages.linearDocument")]
41 LinearDocument(Box<LinearDocument<'a>>),
42 #[serde(rename = "pub.leaflet.pages.canvas")]
43 Canvas(Box<Canvas<'a>>),
44}
45
46impl<'a> LexiconSchema for Content<'a> {
47 fn nsid() -> &'static str {
48 "pub.leaflet.content"
49 }
50 fn def_name() -> &'static str {
51 "main"
52 }
53 fn lexicon_doc() -> LexiconDoc<'static> {
54 lexicon_doc_pub_leaflet_content()
55 }
56 fn validate(&self) -> Result<(), ConstraintError> {
57 Ok(())
58 }
59}
60
61pub mod content_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 Pages;
72 }
73 pub struct Empty(());
75 impl sealed::Sealed for Empty {}
76 impl State for Empty {
77 type Pages = Unset;
78 }
79 pub struct SetPages<S: State = Empty>(PhantomData<fn() -> S>);
81 impl<S: State> sealed::Sealed for SetPages<S> {}
82 impl<S: State> State for SetPages<S> {
83 type Pages = Set<members::pages>;
84 }
85 #[allow(non_camel_case_types)]
87 pub mod members {
88 pub struct pages(());
90 }
91}
92
93pub struct ContentBuilder<'a, S: content_state::State> {
95 _state: PhantomData<fn() -> S>,
96 _fields: (Option<Vec<ContentPagesItem<'a>>>,),
97 _lifetime: PhantomData<&'a ()>,
98}
99
100impl<'a> Content<'a> {
101 pub fn new() -> ContentBuilder<'a, content_state::Empty> {
103 ContentBuilder::new()
104 }
105}
106
107impl<'a> ContentBuilder<'a, content_state::Empty> {
108 pub fn new() -> Self {
110 ContentBuilder {
111 _state: PhantomData,
112 _fields: (None,),
113 _lifetime: PhantomData,
114 }
115 }
116}
117
118impl<'a, S> ContentBuilder<'a, S>
119where
120 S: content_state::State,
121 S::Pages: content_state::IsUnset,
122{
123 pub fn pages(
125 mut self,
126 value: impl Into<Vec<ContentPagesItem<'a>>>,
127 ) -> ContentBuilder<'a, content_state::SetPages<S>> {
128 self._fields.0 = Option::Some(value.into());
129 ContentBuilder {
130 _state: PhantomData,
131 _fields: self._fields,
132 _lifetime: PhantomData,
133 }
134 }
135}
136
137impl<'a, S> ContentBuilder<'a, S>
138where
139 S: content_state::State,
140 S::Pages: content_state::IsSet,
141{
142 pub fn build(self) -> Content<'a> {
144 Content {
145 pages: self._fields.0.unwrap(),
146 extra_data: Default::default(),
147 }
148 }
149 pub fn build_with_data(
151 self,
152 extra_data: BTreeMap<
153 jacquard_common::deps::smol_str::SmolStr,
154 jacquard_common::types::value::Data<'a>,
155 >,
156 ) -> Content<'a> {
157 Content {
158 pages: self._fields.0.unwrap(),
159 extra_data: Some(extra_data),
160 }
161 }
162}
163
164fn lexicon_doc_pub_leaflet_content() -> LexiconDoc<'static> {
165 #[allow(unused_imports)]
166 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
167 use jacquard_lexicon::lexicon::*;
168 use alloc::collections::BTreeMap;
169 LexiconDoc {
170 lexicon: Lexicon::Lexicon1,
171 id: CowStr::new_static("pub.leaflet.content"),
172 defs: {
173 let mut map = BTreeMap::new();
174 map.insert(
175 SmolStr::new_static("main"),
176 LexUserType::Object(LexObject {
177 description: Some(
178 CowStr::new_static("Content format for leaflet documents"),
179 ),
180 required: Some(vec![SmolStr::new_static("pages")]),
181 properties: {
182 #[allow(unused_mut)]
183 let mut map = BTreeMap::new();
184 map.insert(
185 SmolStr::new_static("pages"),
186 LexObjectProperty::Array(LexArray {
187 items: LexArrayItem::Union(LexRefUnion {
188 refs: vec![
189 CowStr::new_static("pub.leaflet.pages.linearDocument"),
190 CowStr::new_static("pub.leaflet.pages.canvas")
191 ],
192 ..Default::default()
193 }),
194 ..Default::default()
195 }),
196 );
197 map
198 },
199 ..Default::default()
200 }),
201 );
202 map
203 },
204 ..Default::default()
205 }
206}