jacquard_api/sh_tangled/
string.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: sh.tangled.string
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 TangledString<'a> {
20    #[serde(borrow)]
21    pub contents: jacquard_common::CowStr<'a>,
22    pub created_at: jacquard_common::types::string::Datetime,
23    #[serde(borrow)]
24    pub description: jacquard_common::CowStr<'a>,
25    #[serde(borrow)]
26    pub filename: jacquard_common::CowStr<'a>,
27}
28
29pub mod tangled_string_state {
30
31    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
32    #[allow(unused)]
33    use ::core::marker::PhantomData;
34    mod sealed {
35        pub trait Sealed {}
36    }
37    /// State trait tracking which required fields have been set
38    pub trait State: sealed::Sealed {
39        type Filename;
40        type Description;
41        type CreatedAt;
42        type Contents;
43    }
44    /// Empty state - all required fields are unset
45    pub struct Empty(());
46    impl sealed::Sealed for Empty {}
47    impl State for Empty {
48        type Filename = Unset;
49        type Description = Unset;
50        type CreatedAt = Unset;
51        type Contents = Unset;
52    }
53    ///State transition - sets the `filename` field to Set
54    pub struct SetFilename<S: State = Empty>(PhantomData<fn() -> S>);
55    impl<S: State> sealed::Sealed for SetFilename<S> {}
56    impl<S: State> State for SetFilename<S> {
57        type Filename = Set<members::filename>;
58        type Description = S::Description;
59        type CreatedAt = S::CreatedAt;
60        type Contents = S::Contents;
61    }
62    ///State transition - sets the `description` field to Set
63    pub struct SetDescription<S: State = Empty>(PhantomData<fn() -> S>);
64    impl<S: State> sealed::Sealed for SetDescription<S> {}
65    impl<S: State> State for SetDescription<S> {
66        type Filename = S::Filename;
67        type Description = Set<members::description>;
68        type CreatedAt = S::CreatedAt;
69        type Contents = S::Contents;
70    }
71    ///State transition - sets the `created_at` field to Set
72    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
73    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
74    impl<S: State> State for SetCreatedAt<S> {
75        type Filename = S::Filename;
76        type Description = S::Description;
77        type CreatedAt = Set<members::created_at>;
78        type Contents = S::Contents;
79    }
80    ///State transition - sets the `contents` field to Set
81    pub struct SetContents<S: State = Empty>(PhantomData<fn() -> S>);
82    impl<S: State> sealed::Sealed for SetContents<S> {}
83    impl<S: State> State for SetContents<S> {
84        type Filename = S::Filename;
85        type Description = S::Description;
86        type CreatedAt = S::CreatedAt;
87        type Contents = Set<members::contents>;
88    }
89    /// Marker types for field names
90    #[allow(non_camel_case_types)]
91    pub mod members {
92        ///Marker type for the `filename` field
93        pub struct filename(());
94        ///Marker type for the `description` field
95        pub struct description(());
96        ///Marker type for the `created_at` field
97        pub struct created_at(());
98        ///Marker type for the `contents` field
99        pub struct contents(());
100    }
101}
102
103/// Builder for constructing an instance of this type
104pub struct TangledStringBuilder<'a, S: tangled_string_state::State> {
105    _phantom_state: ::core::marker::PhantomData<fn() -> S>,
106    __unsafe_private_named: (
107        ::core::option::Option<jacquard_common::CowStr<'a>>,
108        ::core::option::Option<jacquard_common::types::string::Datetime>,
109        ::core::option::Option<jacquard_common::CowStr<'a>>,
110        ::core::option::Option<jacquard_common::CowStr<'a>>,
111    ),
112    _phantom: ::core::marker::PhantomData<&'a ()>,
113}
114
115impl<'a> TangledString<'a> {
116    /// Create a new builder for this type
117    pub fn new() -> TangledStringBuilder<'a, tangled_string_state::Empty> {
118        TangledStringBuilder::new()
119    }
120}
121
122impl<'a> TangledStringBuilder<'a, tangled_string_state::Empty> {
123    /// Create a new builder with all fields unset
124    pub fn new() -> Self {
125        TangledStringBuilder {
126            _phantom_state: ::core::marker::PhantomData,
127            __unsafe_private_named: (None, None, None, None),
128            _phantom: ::core::marker::PhantomData,
129        }
130    }
131}
132
133impl<'a, S> TangledStringBuilder<'a, S>
134where
135    S: tangled_string_state::State,
136    S::Contents: tangled_string_state::IsUnset,
137{
138    /// Set the `contents` field (required)
139    pub fn contents(
140        mut self,
141        value: impl Into<jacquard_common::CowStr<'a>>,
142    ) -> TangledStringBuilder<'a, tangled_string_state::SetContents<S>> {
143        self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
144        TangledStringBuilder {
145            _phantom_state: ::core::marker::PhantomData,
146            __unsafe_private_named: self.__unsafe_private_named,
147            _phantom: ::core::marker::PhantomData,
148        }
149    }
150}
151
152impl<'a, S> TangledStringBuilder<'a, S>
153where
154    S: tangled_string_state::State,
155    S::CreatedAt: tangled_string_state::IsUnset,
156{
157    /// Set the `createdAt` field (required)
158    pub fn created_at(
159        mut self,
160        value: impl Into<jacquard_common::types::string::Datetime>,
161    ) -> TangledStringBuilder<'a, tangled_string_state::SetCreatedAt<S>> {
162        self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
163        TangledStringBuilder {
164            _phantom_state: ::core::marker::PhantomData,
165            __unsafe_private_named: self.__unsafe_private_named,
166            _phantom: ::core::marker::PhantomData,
167        }
168    }
169}
170
171impl<'a, S> TangledStringBuilder<'a, S>
172where
173    S: tangled_string_state::State,
174    S::Description: tangled_string_state::IsUnset,
175{
176    /// Set the `description` field (required)
177    pub fn description(
178        mut self,
179        value: impl Into<jacquard_common::CowStr<'a>>,
180    ) -> TangledStringBuilder<'a, tangled_string_state::SetDescription<S>> {
181        self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into());
182        TangledStringBuilder {
183            _phantom_state: ::core::marker::PhantomData,
184            __unsafe_private_named: self.__unsafe_private_named,
185            _phantom: ::core::marker::PhantomData,
186        }
187    }
188}
189
190impl<'a, S> TangledStringBuilder<'a, S>
191where
192    S: tangled_string_state::State,
193    S::Filename: tangled_string_state::IsUnset,
194{
195    /// Set the `filename` field (required)
196    pub fn filename(
197        mut self,
198        value: impl Into<jacquard_common::CowStr<'a>>,
199    ) -> TangledStringBuilder<'a, tangled_string_state::SetFilename<S>> {
200        self.__unsafe_private_named.3 = ::core::option::Option::Some(value.into());
201        TangledStringBuilder {
202            _phantom_state: ::core::marker::PhantomData,
203            __unsafe_private_named: self.__unsafe_private_named,
204            _phantom: ::core::marker::PhantomData,
205        }
206    }
207}
208
209impl<'a, S> TangledStringBuilder<'a, S>
210where
211    S: tangled_string_state::State,
212    S::Filename: tangled_string_state::IsSet,
213    S::Description: tangled_string_state::IsSet,
214    S::CreatedAt: tangled_string_state::IsSet,
215    S::Contents: tangled_string_state::IsSet,
216{
217    /// Build the final struct
218    pub fn build(self) -> TangledString<'a> {
219        TangledString {
220            contents: self.__unsafe_private_named.0.unwrap(),
221            created_at: self.__unsafe_private_named.1.unwrap(),
222            description: self.__unsafe_private_named.2.unwrap(),
223            filename: self.__unsafe_private_named.3.unwrap(),
224            extra_data: Default::default(),
225        }
226    }
227    /// Build the final struct with custom extra_data
228    pub fn build_with_data(
229        self,
230        extra_data: std::collections::BTreeMap<
231            jacquard_common::smol_str::SmolStr,
232            jacquard_common::types::value::Data<'a>,
233        >,
234    ) -> TangledString<'a> {
235        TangledString {
236            contents: self.__unsafe_private_named.0.unwrap(),
237            created_at: self.__unsafe_private_named.1.unwrap(),
238            description: self.__unsafe_private_named.2.unwrap(),
239            filename: self.__unsafe_private_named.3.unwrap(),
240            extra_data: Some(extra_data),
241        }
242    }
243}
244
245impl<'a> TangledString<'a> {
246    pub fn uri(
247        uri: impl Into<jacquard_common::CowStr<'a>>,
248    ) -> Result<
249        jacquard_common::types::uri::RecordUri<'a, TangledStringRecord>,
250        jacquard_common::types::uri::UriError,
251    > {
252        jacquard_common::types::uri::RecordUri::try_from_uri(
253            jacquard_common::types::string::AtUri::new_cow(uri.into())?,
254        )
255    }
256}
257
258/// Typed wrapper for GetRecord response with this collection's record type.
259#[derive(
260    serde::Serialize,
261    serde::Deserialize,
262    Debug,
263    Clone,
264    PartialEq,
265    Eq,
266    jacquard_derive::IntoStatic
267)]
268#[serde(rename_all = "camelCase")]
269pub struct TangledStringGetRecordOutput<'a> {
270    #[serde(skip_serializing_if = "std::option::Option::is_none")]
271    #[serde(borrow)]
272    pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>,
273    #[serde(borrow)]
274    pub uri: jacquard_common::types::string::AtUri<'a>,
275    #[serde(borrow)]
276    pub value: TangledString<'a>,
277}
278
279impl From<TangledStringGetRecordOutput<'_>> for TangledString<'_> {
280    fn from(output: TangledStringGetRecordOutput<'_>) -> Self {
281        use jacquard_common::IntoStatic;
282        output.value.into_static()
283    }
284}
285
286impl jacquard_common::types::collection::Collection for TangledString<'_> {
287    const NSID: &'static str = "sh.tangled.string";
288    type Record = TangledStringRecord;
289}
290
291/// Marker type for deserializing records from this collection.
292#[derive(Debug, serde::Serialize, serde::Deserialize)]
293pub struct TangledStringRecord;
294impl jacquard_common::xrpc::XrpcResp for TangledStringRecord {
295    const NSID: &'static str = "sh.tangled.string";
296    const ENCODING: &'static str = "application/json";
297    type Output<'de> = TangledStringGetRecordOutput<'de>;
298    type Err<'de> = jacquard_common::types::collection::RecordError<'de>;
299}
300
301impl jacquard_common::types::collection::Collection for TangledStringRecord {
302    const NSID: &'static str = "sh.tangled.string";
303    type Record = TangledStringRecord;
304}
305
306impl<'a> ::jacquard_lexicon::schema::LexiconSchema for TangledString<'a> {
307    fn nsid() -> &'static str {
308        "sh.tangled.string"
309    }
310    fn def_name() -> &'static str {
311        "main"
312    }
313    fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
314        lexicon_doc_sh_tangled_string()
315    }
316    fn validate(
317        &self,
318    ) -> ::std::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
319        {
320            let value = &self.contents;
321            {
322                let count = ::unicode_segmentation::UnicodeSegmentation::graphemes(
323                        value.as_ref(),
324                        true,
325                    )
326                    .count();
327                if count < 1usize {
328                    return Err(::jacquard_lexicon::validation::ConstraintError::MinGraphemes {
329                        path: ::jacquard_lexicon::validation::ValidationPath::from_field(
330                            "contents",
331                        ),
332                        min: 1usize,
333                        actual: count,
334                    });
335                }
336            }
337        }
338        {
339            let value = &self.description;
340            {
341                let count = ::unicode_segmentation::UnicodeSegmentation::graphemes(
342                        value.as_ref(),
343                        true,
344                    )
345                    .count();
346                if count > 280usize {
347                    return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
348                        path: ::jacquard_lexicon::validation::ValidationPath::from_field(
349                            "description",
350                        ),
351                        max: 280usize,
352                        actual: count,
353                    });
354                }
355            }
356        }
357        {
358            let value = &self.filename;
359            {
360                let count = ::unicode_segmentation::UnicodeSegmentation::graphemes(
361                        value.as_ref(),
362                        true,
363                    )
364                    .count();
365                if count > 140usize {
366                    return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
367                        path: ::jacquard_lexicon::validation::ValidationPath::from_field(
368                            "filename",
369                        ),
370                        max: 140usize,
371                        actual: count,
372                    });
373                }
374            }
375        }
376        {
377            let value = &self.filename;
378            {
379                let count = ::unicode_segmentation::UnicodeSegmentation::graphemes(
380                        value.as_ref(),
381                        true,
382                    )
383                    .count();
384                if count < 1usize {
385                    return Err(::jacquard_lexicon::validation::ConstraintError::MinGraphemes {
386                        path: ::jacquard_lexicon::validation::ValidationPath::from_field(
387                            "filename",
388                        ),
389                        min: 1usize,
390                        actual: count,
391                    });
392                }
393            }
394        }
395        Ok(())
396    }
397}
398
399fn lexicon_doc_sh_tangled_string() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
400    ::jacquard_lexicon::lexicon::LexiconDoc {
401        lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
402        id: ::jacquard_common::CowStr::new_static("sh.tangled.string"),
403        revision: None,
404        description: None,
405        defs: {
406            let mut map = ::std::collections::BTreeMap::new();
407            map.insert(
408                ::jacquard_common::smol_str::SmolStr::new_static("main"),
409                ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord {
410                    description: None,
411                    key: Some(::jacquard_common::CowStr::new_static("tid")),
412                    record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject {
413                        description: None,
414                        required: Some(
415                            vec![
416                                ::jacquard_common::smol_str::SmolStr::new_static("filename"),
417                                ::jacquard_common::smol_str::SmolStr::new_static("description"),
418                                ::jacquard_common::smol_str::SmolStr::new_static("createdAt"),
419                                ::jacquard_common::smol_str::SmolStr::new_static("contents")
420                            ],
421                        ),
422                        nullable: None,
423                        properties: {
424                            #[allow(unused_mut)]
425                            let mut map = ::std::collections::BTreeMap::new();
426                            map.insert(
427                                ::jacquard_common::smol_str::SmolStr::new_static(
428                                    "contents",
429                                ),
430                                ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
431                                    description: None,
432                                    format: None,
433                                    default: None,
434                                    min_length: None,
435                                    max_length: None,
436                                    min_graphemes: Some(1usize),
437                                    max_graphemes: None,
438                                    r#enum: None,
439                                    r#const: None,
440                                    known_values: None,
441                                }),
442                            );
443                            map.insert(
444                                ::jacquard_common::smol_str::SmolStr::new_static(
445                                    "createdAt",
446                                ),
447                                ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
448                                    description: None,
449                                    format: Some(
450                                        ::jacquard_lexicon::lexicon::LexStringFormat::Datetime,
451                                    ),
452                                    default: None,
453                                    min_length: None,
454                                    max_length: None,
455                                    min_graphemes: None,
456                                    max_graphemes: None,
457                                    r#enum: None,
458                                    r#const: None,
459                                    known_values: None,
460                                }),
461                            );
462                            map.insert(
463                                ::jacquard_common::smol_str::SmolStr::new_static(
464                                    "description",
465                                ),
466                                ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
467                                    description: None,
468                                    format: None,
469                                    default: None,
470                                    min_length: None,
471                                    max_length: None,
472                                    min_graphemes: None,
473                                    max_graphemes: Some(280usize),
474                                    r#enum: None,
475                                    r#const: None,
476                                    known_values: None,
477                                }),
478                            );
479                            map.insert(
480                                ::jacquard_common::smol_str::SmolStr::new_static(
481                                    "filename",
482                                ),
483                                ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
484                                    description: None,
485                                    format: None,
486                                    default: None,
487                                    min_length: None,
488                                    max_length: None,
489                                    min_graphemes: Some(1usize),
490                                    max_graphemes: Some(140usize),
491                                    r#enum: None,
492                                    r#const: None,
493                                    known_values: None,
494                                }),
495                            );
496                            map
497                        },
498                    }),
499                }),
500            );
501            map
502        },
503    }
504}