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#[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    /// State trait tracking which required fields have been set
35    pub trait State: sealed::Sealed {
36        type Text;
37        type Url;
38    }
39    /// Empty state - all required fields are unset
40    pub struct Empty(());
41    impl sealed::Sealed for Empty {}
42    impl State for Empty {
43        type Text = Unset;
44        type Url = Unset;
45    }
46    ///State transition - sets the `text` field to Set
47    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    ///State transition - sets the `url` field to Set
54    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    /// Marker types for field names
61    #[allow(non_camel_case_types)]
62    pub mod members {
63        ///Marker type for the `text` field
64        pub struct text(());
65        ///Marker type for the `url` field
66        pub struct url(());
67    }
68}
69
70/// Builder for constructing an instance of this type
71pub 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    /// Create a new builder for this type
82    pub fn new() -> ButtonBuilder<'a, button_state::Empty> {
83        ButtonBuilder::new()
84    }
85}
86
87impl<'a> ButtonBuilder<'a, button_state::Empty> {
88    /// Create a new builder with all fields unset
89    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    /// Set the `text` field (required)
104    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    /// Set the `url` field (required)
123    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    /// Build the final struct
143    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    /// Build the final struct with custom extra_data
151    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}