jacquard-api 0.12.0-beta.2

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

#[allow(unused_imports)]
use alloc::collections::BTreeMap;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
/// A physical location in the form of a street address.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(
    rename_all = "camelCase",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Address<S: BosStr = DefaultStr> {
    ///The ISO 3166 country code. Preferably the 2-letter code.
    pub country: S,
    ///The locality of the region. For example, a city in the USA.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub locality: Option<S>,
    ///The name of the location.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<S>,
    ///The postal code of the location.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub postal_code: Option<S>,
    ///The administrative region of the country. For example, a state in the USA.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub region: Option<S>,
    ///The street address.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub street: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for Address<S> {
    fn nsid() -> &'static str {
        "community.lexicon.location.address"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_community_lexicon_location_address()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.country;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("country"),
                    max: 10usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.country;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 2usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("country"),
                    min: 2usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

fn lexicon_doc_community_lexicon_location_address() -> LexiconDoc<'static> {
    use alloc::collections::BTreeMap;
    #[allow(unused_imports)]
    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
    use jacquard_lexicon::lexicon::*;
    LexiconDoc {
        lexicon: Lexicon::Lexicon1,
        id: CowStr::new_static("community.lexicon.location.address"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A physical location in the form of a street address.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("country")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("country"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The ISO 3166 country code. Preferably the 2-letter code.",
                                    ),
                                ),
                                min_length: Some(2usize),
                                max_length: Some(10usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("locality"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The locality of the region. For example, a city in the USA.",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The name of the location."),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("postalCode"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The postal code of the location."),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("region"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The administrative region of the country. For example, a state in the USA.",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("street"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The street address."),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}