Skip to main content

jacquard_api/pub_leaflet/blocks/
button.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: pub.leaflet.blocks.button
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;
13use jacquard_common::CowStr;
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::types::string::UriValue;
18use jacquard_derive::{IntoStatic, lexicon};
19use jacquard_lexicon::lexicon::LexiconDoc;
20use jacquard_lexicon::schema::LexiconSchema;
21
22#[allow(unused_imports)]
23use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
24use serde::{Serialize, Deserialize};
25
26#[lexicon]
27#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
28#[serde(rename_all = "camelCase")]
29pub struct Button<'a> {
30    #[serde(borrow)]
31    pub text: CowStr<'a>,
32    #[serde(borrow)]
33    pub url: UriValue<'a>,
34}
35
36impl<'a> LexiconSchema for Button<'a> {
37    fn nsid() -> &'static str {
38        "pub.leaflet.blocks.button"
39    }
40    fn def_name() -> &'static str {
41        "main"
42    }
43    fn lexicon_doc() -> LexiconDoc<'static> {
44        lexicon_doc_pub_leaflet_blocks_button()
45    }
46    fn validate(&self) -> Result<(), ConstraintError> {
47        Ok(())
48    }
49}
50
51pub mod button_state {
52
53    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
54    #[allow(unused)]
55    use ::core::marker::PhantomData;
56    mod sealed {
57        pub trait Sealed {}
58    }
59    /// State trait tracking which required fields have been set
60    pub trait State: sealed::Sealed {
61        type Text;
62        type Url;
63    }
64    /// Empty state - all required fields are unset
65    pub struct Empty(());
66    impl sealed::Sealed for Empty {}
67    impl State for Empty {
68        type Text = Unset;
69        type Url = Unset;
70    }
71    ///State transition - sets the `text` field to Set
72    pub struct SetText<S: State = Empty>(PhantomData<fn() -> S>);
73    impl<S: State> sealed::Sealed for SetText<S> {}
74    impl<S: State> State for SetText<S> {
75        type Text = Set<members::text>;
76        type Url = S::Url;
77    }
78    ///State transition - sets the `url` field to Set
79    pub struct SetUrl<S: State = Empty>(PhantomData<fn() -> S>);
80    impl<S: State> sealed::Sealed for SetUrl<S> {}
81    impl<S: State> State for SetUrl<S> {
82        type Text = S::Text;
83        type Url = Set<members::url>;
84    }
85    /// Marker types for field names
86    #[allow(non_camel_case_types)]
87    pub mod members {
88        ///Marker type for the `text` field
89        pub struct text(());
90        ///Marker type for the `url` field
91        pub struct url(());
92    }
93}
94
95/// Builder for constructing an instance of this type
96pub struct ButtonBuilder<'a, S: button_state::State> {
97    _state: PhantomData<fn() -> S>,
98    _fields: (Option<CowStr<'a>>, Option<UriValue<'a>>),
99    _lifetime: PhantomData<&'a ()>,
100}
101
102impl<'a> Button<'a> {
103    /// Create a new builder for this type
104    pub fn new() -> ButtonBuilder<'a, button_state::Empty> {
105        ButtonBuilder::new()
106    }
107}
108
109impl<'a> ButtonBuilder<'a, button_state::Empty> {
110    /// Create a new builder with all fields unset
111    pub fn new() -> Self {
112        ButtonBuilder {
113            _state: PhantomData,
114            _fields: (None, None),
115            _lifetime: PhantomData,
116        }
117    }
118}
119
120impl<'a, S> ButtonBuilder<'a, S>
121where
122    S: button_state::State,
123    S::Text: button_state::IsUnset,
124{
125    /// Set the `text` field (required)
126    pub fn text(
127        mut self,
128        value: impl Into<CowStr<'a>>,
129    ) -> ButtonBuilder<'a, button_state::SetText<S>> {
130        self._fields.0 = Option::Some(value.into());
131        ButtonBuilder {
132            _state: PhantomData,
133            _fields: self._fields,
134            _lifetime: PhantomData,
135        }
136    }
137}
138
139impl<'a, S> ButtonBuilder<'a, S>
140where
141    S: button_state::State,
142    S::Url: button_state::IsUnset,
143{
144    /// Set the `url` field (required)
145    pub fn url(
146        mut self,
147        value: impl Into<UriValue<'a>>,
148    ) -> ButtonBuilder<'a, button_state::SetUrl<S>> {
149        self._fields.1 = Option::Some(value.into());
150        ButtonBuilder {
151            _state: PhantomData,
152            _fields: self._fields,
153            _lifetime: PhantomData,
154        }
155    }
156}
157
158impl<'a, S> ButtonBuilder<'a, S>
159where
160    S: button_state::State,
161    S::Text: button_state::IsSet,
162    S::Url: button_state::IsSet,
163{
164    /// Build the final struct
165    pub fn build(self) -> Button<'a> {
166        Button {
167            text: self._fields.0.unwrap(),
168            url: self._fields.1.unwrap(),
169            extra_data: Default::default(),
170        }
171    }
172    /// Build the final struct with custom extra_data
173    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    ) -> Button<'a> {
180        Button {
181            text: self._fields.0.unwrap(),
182            url: self._fields.1.unwrap(),
183            extra_data: Some(extra_data),
184        }
185    }
186}
187
188fn lexicon_doc_pub_leaflet_blocks_button() -> 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("pub.leaflet.blocks.button"),
196        defs: {
197            let mut map = BTreeMap::new();
198            map.insert(
199                SmolStr::new_static("main"),
200                LexUserType::Object(LexObject {
201                    required: Some(
202                        vec![SmolStr::new_static("text"), SmolStr::new_static("url")],
203                    ),
204                    properties: {
205                        #[allow(unused_mut)]
206                        let mut map = BTreeMap::new();
207                        map.insert(
208                            SmolStr::new_static("text"),
209                            LexObjectProperty::String(LexString { ..Default::default() }),
210                        );
211                        map.insert(
212                            SmolStr::new_static("url"),
213                            LexObjectProperty::String(LexString {
214                                format: Some(LexStringFormat::Uri),
215                                ..Default::default()
216                            }),
217                        );
218                        map
219                    },
220                    ..Default::default()
221                }),
222            );
223            map
224        },
225        ..Default::default()
226    }
227}