jacquard-api 0.10.2

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: fyi.questionable.richtext.header
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[jacquard_derive::lexicon]
#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct Header<'a> {
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub facets: std::option::Option<
        Vec<crate::fyi_questionable::richtext::facet::Facet<'a>>,
    >,
    pub level: i64,
    #[serde(borrow)]
    pub plaintext: jacquard_common::CowStr<'a>,
}

pub mod header_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 Plaintext;
        type Level;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Plaintext = Unset;
        type Level = Unset;
    }
    ///State transition - sets the `plaintext` field to Set
    pub struct SetPlaintext<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPlaintext<S> {}
    impl<S: State> State for SetPlaintext<S> {
        type Plaintext = Set<members::plaintext>;
        type Level = S::Level;
    }
    ///State transition - sets the `level` field to Set
    pub struct SetLevel<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetLevel<S> {}
    impl<S: State> State for SetLevel<S> {
        type Plaintext = S::Plaintext;
        type Level = Set<members::level>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `plaintext` field
        pub struct plaintext(());
        ///Marker type for the `level` field
        pub struct level(());
    }
}

/// Builder for constructing an instance of this type
pub struct HeaderBuilder<'a, S: header_state::State> {
    _phantom_state: ::core::marker::PhantomData<fn() -> S>,
    __unsafe_private_named: (
        ::core::option::Option<Vec<crate::fyi_questionable::richtext::facet::Facet<'a>>>,
        ::core::option::Option<i64>,
        ::core::option::Option<jacquard_common::CowStr<'a>>,
    ),
    _phantom: ::core::marker::PhantomData<&'a ()>,
}

impl<'a> Header<'a> {
    /// Create a new builder for this type
    pub fn new() -> HeaderBuilder<'a, header_state::Empty> {
        HeaderBuilder::new()
    }
}

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

impl<'a, S: header_state::State> HeaderBuilder<'a, S> {
    /// Set the `facets` field (optional)
    pub fn facets(
        mut self,
        value: impl Into<
            Option<Vec<crate::fyi_questionable::richtext::facet::Facet<'a>>>,
        >,
    ) -> Self {
        self.__unsafe_private_named.0 = value.into();
        self
    }
    /// Set the `facets` field to an Option value (optional)
    pub fn maybe_facets(
        mut self,
        value: Option<Vec<crate::fyi_questionable::richtext::facet::Facet<'a>>>,
    ) -> Self {
        self.__unsafe_private_named.0 = value;
        self
    }
}

impl<'a, S> HeaderBuilder<'a, S>
where
    S: header_state::State,
    S::Level: header_state::IsUnset,
{
    /// Set the `level` field (required)
    pub fn level(
        mut self,
        value: impl Into<i64>,
    ) -> HeaderBuilder<'a, header_state::SetLevel<S>> {
        self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
        HeaderBuilder {
            _phantom_state: ::core::marker::PhantomData,
            __unsafe_private_named: self.__unsafe_private_named,
            _phantom: ::core::marker::PhantomData,
        }
    }
}

impl<'a, S> HeaderBuilder<'a, S>
where
    S: header_state::State,
    S::Plaintext: header_state::IsUnset,
{
    /// Set the `plaintext` field (required)
    pub fn plaintext(
        mut self,
        value: impl Into<jacquard_common::CowStr<'a>>,
    ) -> HeaderBuilder<'a, header_state::SetPlaintext<S>> {
        self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into());
        HeaderBuilder {
            _phantom_state: ::core::marker::PhantomData,
            __unsafe_private_named: self.__unsafe_private_named,
            _phantom: ::core::marker::PhantomData,
        }
    }
}

impl<'a, S> HeaderBuilder<'a, S>
where
    S: header_state::State,
    S::Plaintext: header_state::IsSet,
    S::Level: header_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Header<'a> {
        Header {
            facets: self.__unsafe_private_named.0,
            level: self.__unsafe_private_named.1.unwrap(),
            plaintext: self.__unsafe_private_named.2.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>,
        >,
    ) -> Header<'a> {
        Header {
            facets: self.__unsafe_private_named.0,
            level: self.__unsafe_private_named.1.unwrap(),
            plaintext: self.__unsafe_private_named.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_fyi_questionable_richtext_header() -> ::jacquard_lexicon::lexicon::LexiconDoc<
    'static,
> {
    ::jacquard_lexicon::lexicon::LexiconDoc {
        lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
        id: ::jacquard_common::CowStr::new_static("fyi.questionable.richtext.header"),
        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::Object(::jacquard_lexicon::lexicon::LexObject {
                    description: None,
                    required: Some(
                        vec![
                            ::jacquard_common::deps::smol_str::SmolStr::new_static("plaintext"),
                            ::jacquard_common::deps::smol_str::SmolStr::new_static("level")
                        ],
                    ),
                    nullable: None,
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = ::alloc::collections::BTreeMap::new();
                        map.insert(
                            ::jacquard_common::deps::smol_str::SmolStr::new_static(
                                "facets",
                            ),
                            ::jacquard_lexicon::lexicon::LexObjectProperty::Array(::jacquard_lexicon::lexicon::LexArray {
                                description: None,
                                items: ::jacquard_lexicon::lexicon::LexArrayItem::Ref(::jacquard_lexicon::lexicon::LexRef {
                                    description: None,
                                    r#ref: ::jacquard_common::CowStr::new_static(
                                        "fyi.questionable.richtext.facet",
                                    ),
                                }),
                                min_length: None,
                                max_length: None,
                            }),
                        );
                        map.insert(
                            ::jacquard_common::deps::smol_str::SmolStr::new_static(
                                "level",
                            ),
                            ::jacquard_lexicon::lexicon::LexObjectProperty::Integer(::jacquard_lexicon::lexicon::LexInteger {
                                description: None,
                                default: None,
                                minimum: Some(1i64),
                                maximum: Some(6i64),
                                r#enum: None,
                                r#const: None,
                            }),
                        );
                        map.insert(
                            ::jacquard_common::deps::smol_str::SmolStr::new_static(
                                "plaintext",
                            ),
                            ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
                                description: None,
                                format: None,
                                default: None,
                                min_length: None,
                                max_length: Some(2000usize),
                                min_graphemes: None,
                                max_graphemes: Some(1000usize),
                                r#enum: None,
                                r#const: None,
                                known_values: None,
                            }),
                        );
                        map
                    },
                }),
            );
            map
        },
    }
}

impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Header<'a> {
    fn nsid() -> &'static str {
        "fyi.questionable.richtext.header"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
        lexicon_doc_fyi_questionable_richtext_header()
    }
    fn validate(
        &self,
    ) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
        {
            let value = &self.level;
            if *value > 6i64 {
                return Err(::jacquard_lexicon::validation::ConstraintError::Maximum {
                    path: ::jacquard_lexicon::validation::ValidationPath::from_field(
                        "level",
                    ),
                    max: 6i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.level;
            if *value < 1i64 {
                return Err(::jacquard_lexicon::validation::ConstraintError::Minimum {
                    path: ::jacquard_lexicon::validation::ValidationPath::from_field(
                        "level",
                    ),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.plaintext;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2000usize {
                return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
                    path: ::jacquard_lexicon::validation::ValidationPath::from_field(
                        "plaintext",
                    ),
                    max: 2000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.plaintext;
            {
                let count = jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation::graphemes(
                        value.as_ref(),
                        true,
                    )
                    .count();
                if count > 1000usize {
                    return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
                        path: ::jacquard_lexicon::validation::ValidationPath::from_field(
                            "plaintext",
                        ),
                        max: 1000usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}