jacquard_api/pub_leaflet/blocks/
button.rs1#[jacquard_derive::lexicon]
9#[derive(
10 serde::Serialize,
11 serde::Deserialize,
12 Debug,
13 Clone,
14 PartialEq,
15 Eq,
16 jacquard_derive::IntoStatic
17)]
18#[serde(rename_all = "camelCase")]
19pub struct Button<'a> {
20 #[serde(borrow)]
21 pub text: jacquard_common::CowStr<'a>,
22 #[serde(borrow)]
23 pub url: jacquard_common::types::string::Uri<'a>,
24}
25
26pub mod button_state {
27
28 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
29 #[allow(unused)]
30 use ::core::marker::PhantomData;
31 mod sealed {
32 pub trait Sealed {}
33 }
34 pub trait State: sealed::Sealed {
36 type Text;
37 type Url;
38 }
39 pub struct Empty(());
41 impl sealed::Sealed for Empty {}
42 impl State for Empty {
43 type Text = Unset;
44 type Url = Unset;
45 }
46 pub struct SetText<S: State = Empty>(PhantomData<fn() -> S>);
48 impl<S: State> sealed::Sealed for SetText<S> {}
49 impl<S: State> State for SetText<S> {
50 type Text = Set<members::text>;
51 type Url = S::Url;
52 }
53 pub struct SetUrl<S: State = Empty>(PhantomData<fn() -> S>);
55 impl<S: State> sealed::Sealed for SetUrl<S> {}
56 impl<S: State> State for SetUrl<S> {
57 type Text = S::Text;
58 type Url = Set<members::url>;
59 }
60 #[allow(non_camel_case_types)]
62 pub mod members {
63 pub struct text(());
65 pub struct url(());
67 }
68}
69
70pub struct ButtonBuilder<'a, S: button_state::State> {
72 _phantom_state: ::core::marker::PhantomData<fn() -> S>,
73 __unsafe_private_named: (
74 ::core::option::Option<jacquard_common::CowStr<'a>>,
75 ::core::option::Option<jacquard_common::types::string::Uri<'a>>,
76 ),
77 _phantom: ::core::marker::PhantomData<&'a ()>,
78}
79
80impl<'a> Button<'a> {
81 pub fn new() -> ButtonBuilder<'a, button_state::Empty> {
83 ButtonBuilder::new()
84 }
85}
86
87impl<'a> ButtonBuilder<'a, button_state::Empty> {
88 pub fn new() -> Self {
90 ButtonBuilder {
91 _phantom_state: ::core::marker::PhantomData,
92 __unsafe_private_named: (None, None),
93 _phantom: ::core::marker::PhantomData,
94 }
95 }
96}
97
98impl<'a, S> ButtonBuilder<'a, S>
99where
100 S: button_state::State,
101 S::Text: button_state::IsUnset,
102{
103 pub fn text(
105 mut self,
106 value: impl Into<jacquard_common::CowStr<'a>>,
107 ) -> ButtonBuilder<'a, button_state::SetText<S>> {
108 self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
109 ButtonBuilder {
110 _phantom_state: ::core::marker::PhantomData,
111 __unsafe_private_named: self.__unsafe_private_named,
112 _phantom: ::core::marker::PhantomData,
113 }
114 }
115}
116
117impl<'a, S> ButtonBuilder<'a, S>
118where
119 S: button_state::State,
120 S::Url: button_state::IsUnset,
121{
122 pub fn url(
124 mut self,
125 value: impl Into<jacquard_common::types::string::Uri<'a>>,
126 ) -> ButtonBuilder<'a, button_state::SetUrl<S>> {
127 self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
128 ButtonBuilder {
129 _phantom_state: ::core::marker::PhantomData,
130 __unsafe_private_named: self.__unsafe_private_named,
131 _phantom: ::core::marker::PhantomData,
132 }
133 }
134}
135
136impl<'a, S> ButtonBuilder<'a, S>
137where
138 S: button_state::State,
139 S::Text: button_state::IsSet,
140 S::Url: button_state::IsSet,
141{
142 pub fn build(self) -> Button<'a> {
144 Button {
145 text: self.__unsafe_private_named.0.unwrap(),
146 url: self.__unsafe_private_named.1.unwrap(),
147 extra_data: Default::default(),
148 }
149 }
150 pub fn build_with_data(
152 self,
153 extra_data: std::collections::BTreeMap<
154 jacquard_common::smol_str::SmolStr,
155 jacquard_common::types::value::Data<'a>,
156 >,
157 ) -> Button<'a> {
158 Button {
159 text: self.__unsafe_private_named.0.unwrap(),
160 url: self.__unsafe_private_named.1.unwrap(),
161 extra_data: Some(extra_data),
162 }
163 }
164}
165
166fn lexicon_doc_pub_leaflet_blocks_button() -> ::jacquard_lexicon::lexicon::LexiconDoc<
167 'static,
168> {
169 ::jacquard_lexicon::lexicon::LexiconDoc {
170 lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
171 id: ::jacquard_common::CowStr::new_static("pub.leaflet.blocks.button"),
172 revision: None,
173 description: None,
174 defs: {
175 let mut map = ::std::collections::BTreeMap::new();
176 map.insert(
177 ::jacquard_common::smol_str::SmolStr::new_static("main"),
178 ::jacquard_lexicon::lexicon::LexUserType::Object(::jacquard_lexicon::lexicon::LexObject {
179 description: None,
180 required: Some(
181 vec![
182 ::jacquard_common::smol_str::SmolStr::new_static("text"),
183 ::jacquard_common::smol_str::SmolStr::new_static("url")
184 ],
185 ),
186 nullable: None,
187 properties: {
188 #[allow(unused_mut)]
189 let mut map = ::std::collections::BTreeMap::new();
190 map.insert(
191 ::jacquard_common::smol_str::SmolStr::new_static("text"),
192 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
193 description: None,
194 format: None,
195 default: None,
196 min_length: None,
197 max_length: None,
198 min_graphemes: None,
199 max_graphemes: None,
200 r#enum: None,
201 r#const: None,
202 known_values: None,
203 }),
204 );
205 map.insert(
206 ::jacquard_common::smol_str::SmolStr::new_static("url"),
207 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
208 description: None,
209 format: Some(
210 ::jacquard_lexicon::lexicon::LexStringFormat::Uri,
211 ),
212 default: None,
213 min_length: None,
214 max_length: None,
215 min_graphemes: None,
216 max_graphemes: None,
217 r#enum: None,
218 r#const: None,
219 known_values: None,
220 }),
221 );
222 map
223 },
224 }),
225 );
226 map
227 },
228 }
229}
230
231impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Button<'a> {
232 fn nsid() -> &'static str {
233 "pub.leaflet.blocks.button"
234 }
235 fn def_name() -> &'static str {
236 "main"
237 }
238 fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
239 lexicon_doc_pub_leaflet_blocks_button()
240 }
241 fn validate(
242 &self,
243 ) -> ::std::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
244 Ok(())
245 }
246}