jacquard-api 0.10.2

Generated AT Protocol API bindings for Jacquard
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: uk.skyblur.preference
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

/// A declaration of a Skyblur account.
#[jacquard_derive::lexicon]
#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct Preference<'a> {
    #[serde(borrow)]
    pub my_page: crate::uk_skyblur::preference::MyPage<'a>,
}

pub mod preference_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type MyPage;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type MyPage = Unset;
    }
    ///State transition - sets the `my_page` field to Set
    pub struct SetMyPage<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMyPage<S> {}
    impl<S: State> State for SetMyPage<S> {
        type MyPage = Set<members::my_page>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `my_page` field
        pub struct my_page(());
    }
}

/// Builder for constructing an instance of this type
pub struct PreferenceBuilder<'a, S: preference_state::State> {
    _phantom_state: ::core::marker::PhantomData<fn() -> S>,
    __unsafe_private_named: (
        ::core::option::Option<crate::uk_skyblur::preference::MyPage<'a>>,
    ),
    _phantom: ::core::marker::PhantomData<&'a ()>,
}

impl<'a> Preference<'a> {
    /// Create a new builder for this type
    pub fn new() -> PreferenceBuilder<'a, preference_state::Empty> {
        PreferenceBuilder::new()
    }
}

impl<'a> PreferenceBuilder<'a, preference_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        PreferenceBuilder {
            _phantom_state: ::core::marker::PhantomData,
            __unsafe_private_named: (None,),
            _phantom: ::core::marker::PhantomData,
        }
    }
}

impl<'a, S> PreferenceBuilder<'a, S>
where
    S: preference_state::State,
    S::MyPage: preference_state::IsUnset,
{
    /// Set the `myPage` field (required)
    pub fn my_page(
        mut self,
        value: impl Into<crate::uk_skyblur::preference::MyPage<'a>>,
    ) -> PreferenceBuilder<'a, preference_state::SetMyPage<S>> {
        self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
        PreferenceBuilder {
            _phantom_state: ::core::marker::PhantomData,
            __unsafe_private_named: self.__unsafe_private_named,
            _phantom: ::core::marker::PhantomData,
        }
    }
}

impl<'a, S> PreferenceBuilder<'a, S>
where
    S: preference_state::State,
    S::MyPage: preference_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Preference<'a> {
        Preference {
            my_page: self.__unsafe_private_named.0.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: std::collections::BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Preference<'a> {
        Preference {
            my_page: self.__unsafe_private_named.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

impl<'a> Preference<'a> {
    pub fn uri(
        uri: impl Into<jacquard_common::CowStr<'a>>,
    ) -> Result<
        jacquard_common::types::uri::RecordUri<'a, PreferenceRecord>,
        jacquard_common::types::uri::UriError,
    > {
        jacquard_common::types::uri::RecordUri::try_from_uri(
            jacquard_common::types::string::AtUri::new_cow(uri.into())?,
        )
    }
}

/// Typed wrapper for GetRecord response with this collection's record type.
#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct PreferenceGetRecordOutput<'a> {
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>,
    #[serde(borrow)]
    pub uri: jacquard_common::types::string::AtUri<'a>,
    #[serde(borrow)]
    pub value: Preference<'a>,
}

impl From<PreferenceGetRecordOutput<'_>> for Preference<'_> {
    fn from(output: PreferenceGetRecordOutput<'_>) -> Self {
        use jacquard_common::IntoStatic;
        output.value.into_static()
    }
}

impl jacquard_common::types::collection::Collection for Preference<'_> {
    const NSID: &'static str = "uk.skyblur.preference";
    type Record = PreferenceRecord;
}

/// Marker type for deserializing records from this collection.
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct PreferenceRecord;
impl jacquard_common::xrpc::XrpcResp for PreferenceRecord {
    const NSID: &'static str = "uk.skyblur.preference";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = PreferenceGetRecordOutput<'de>;
    type Err<'de> = jacquard_common::types::collection::RecordError<'de>;
}

impl jacquard_common::types::collection::Collection for PreferenceRecord {
    const NSID: &'static str = "uk.skyblur.preference";
    type Record = PreferenceRecord;
}

impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Preference<'a> {
    fn nsid() -> &'static str {
        "uk.skyblur.preference"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
        lexicon_doc_uk_skyblur_preference()
    }
    fn validate(
        &self,
    ) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
        Ok(())
    }
}

fn lexicon_doc_uk_skyblur_preference() -> ::jacquard_lexicon::lexicon::LexiconDoc<
    'static,
> {
    ::jacquard_lexicon::lexicon::LexiconDoc {
        lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
        id: ::jacquard_common::CowStr::new_static("uk.skyblur.preference"),
        revision: None,
        description: None,
        defs: {
            let mut map = ::alloc::collections::BTreeMap::new();
            map.insert(
                ::jacquard_common::deps::smol_str::SmolStr::new_static("main"),
                ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord {
                    description: Some(
                        ::jacquard_common::CowStr::new_static(
                            "A declaration of a Skyblur account.",
                        ),
                    ),
                    key: Some(::jacquard_common::CowStr::new_static("literal:self")),
                    record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject {
                        description: None,
                        required: Some(
                            vec![
                                ::jacquard_common::deps::smol_str::SmolStr::new_static("myPage")
                            ],
                        ),
                        nullable: None,
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = ::alloc::collections::BTreeMap::new();
                            map.insert(
                                ::jacquard_common::deps::smol_str::SmolStr::new_static(
                                    "myPage",
                                ),
                                ::jacquard_lexicon::lexicon::LexObjectProperty::Union(::jacquard_lexicon::lexicon::LexRefUnion {
                                    description: None,
                                    refs: vec![
                                        ::jacquard_common::CowStr::new_static("uk.skyblur.preference#myPage")
                                    ],
                                    closed: None,
                                }),
                            );
                            map
                        },
                    }),
                }),
            );
            map.insert(
                ::jacquard_common::deps::smol_str::SmolStr::new_static("myPage"),
                ::jacquard_lexicon::lexicon::LexUserType::Object(::jacquard_lexicon::lexicon::LexObject {
                    description: None,
                    required: Some(
                        vec![
                            ::jacquard_common::deps::smol_str::SmolStr::new_static("isUseMyPage")
                        ],
                    ),
                    nullable: None,
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = ::alloc::collections::BTreeMap::new();
                        map.insert(
                            ::jacquard_common::deps::smol_str::SmolStr::new_static(
                                "description",
                            ),
                            ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
                                description: Some(
                                    ::jacquard_common::CowStr::new_static(
                                        "Define the description displayed on MyPage.",
                                    ),
                                ),
                                format: None,
                                default: None,
                                min_length: None,
                                max_length: Some(10000usize),
                                min_graphemes: None,
                                max_graphemes: Some(100000usize),
                                r#enum: None,
                                r#const: None,
                                known_values: None,
                            }),
                        );
                        map.insert(
                            ::jacquard_common::deps::smol_str::SmolStr::new_static(
                                "isUseMyPage",
                            ),
                            ::jacquard_lexicon::lexicon::LexObjectProperty::Boolean(::jacquard_lexicon::lexicon::LexBoolean {
                                description: None,
                                default: None,
                                r#const: None,
                            }),
                        );
                        map
                    },
                }),
            );
            map
        },
    }
}

#[jacquard_derive::lexicon]
#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct MyPage<'a> {
    ///Define the description displayed on MyPage.
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub description: std::option::Option<jacquard_common::CowStr<'a>>,
    ///If this item is true, MyPage will be displayed.
    pub is_use_my_page: bool,
}

pub mod my_page_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type IsUseMyPage;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type IsUseMyPage = Unset;
    }
    ///State transition - sets the `is_use_my_page` field to Set
    pub struct SetIsUseMyPage<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetIsUseMyPage<S> {}
    impl<S: State> State for SetIsUseMyPage<S> {
        type IsUseMyPage = Set<members::is_use_my_page>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `is_use_my_page` field
        pub struct is_use_my_page(());
    }
}

/// Builder for constructing an instance of this type
pub struct MyPageBuilder<'a, S: my_page_state::State> {
    _phantom_state: ::core::marker::PhantomData<fn() -> S>,
    __unsafe_private_named: (
        ::core::option::Option<jacquard_common::CowStr<'a>>,
        ::core::option::Option<bool>,
    ),
    _phantom: ::core::marker::PhantomData<&'a ()>,
}

impl<'a> MyPage<'a> {
    /// Create a new builder for this type
    pub fn new() -> MyPageBuilder<'a, my_page_state::Empty> {
        MyPageBuilder::new()
    }
}

impl<'a> MyPageBuilder<'a, my_page_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        MyPageBuilder {
            _phantom_state: ::core::marker::PhantomData,
            __unsafe_private_named: (None, None),
            _phantom: ::core::marker::PhantomData,
        }
    }
}

impl<'a, S: my_page_state::State> MyPageBuilder<'a, S> {
    /// Set the `description` field (optional)
    pub fn description(
        mut self,
        value: impl Into<Option<jacquard_common::CowStr<'a>>>,
    ) -> Self {
        self.__unsafe_private_named.0 = value.into();
        self
    }
    /// Set the `description` field to an Option value (optional)
    pub fn maybe_description(
        mut self,
        value: Option<jacquard_common::CowStr<'a>>,
    ) -> Self {
        self.__unsafe_private_named.0 = value;
        self
    }
}

impl<'a, S> MyPageBuilder<'a, S>
where
    S: my_page_state::State,
    S::IsUseMyPage: my_page_state::IsUnset,
{
    /// Set the `isUseMyPage` field (required)
    pub fn is_use_my_page(
        mut self,
        value: impl Into<bool>,
    ) -> MyPageBuilder<'a, my_page_state::SetIsUseMyPage<S>> {
        self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
        MyPageBuilder {
            _phantom_state: ::core::marker::PhantomData,
            __unsafe_private_named: self.__unsafe_private_named,
            _phantom: ::core::marker::PhantomData,
        }
    }
}

impl<'a, S> MyPageBuilder<'a, S>
where
    S: my_page_state::State,
    S::IsUseMyPage: my_page_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> MyPage<'a> {
        MyPage {
            description: self.__unsafe_private_named.0,
            is_use_my_page: self.__unsafe_private_named.1.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: std::collections::BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> MyPage<'a> {
        MyPage {
            description: self.__unsafe_private_named.0,
            is_use_my_page: self.__unsafe_private_named.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

impl<'a> ::jacquard_lexicon::schema::LexiconSchema for MyPage<'a> {
    fn nsid() -> &'static str {
        "uk.skyblur.preference"
    }
    fn def_name() -> &'static str {
        "myPage"
    }
    fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
        lexicon_doc_uk_skyblur_preference()
    }
    fn validate(
        &self,
    ) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
        if let Some(ref value) = self.description {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10000usize {
                return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
                    path: ::jacquard_lexicon::validation::ValidationPath::from_field(
                        "description",
                    ),
                    max: 10000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.description {
            {
                let count = jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation::graphemes(
                        value.as_ref(),
                        true,
                    )
                    .count();
                if count > 100000usize {
                    return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
                        path: ::jacquard_lexicon::validation::ValidationPath::from_field(
                            "description",
                        ),
                        max: 100000usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}