// @generated by jacquard-lexicon. DO NOT EDIT. // // Lexicon: test.collision.option // // 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; #[allow(unused_imports)] use core::marker::PhantomData; use jacquard_common::{CowStr, BosStr, 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::{Serialize, Deserialize}; use crate::pretty::test_collision::option; /// An object with optional fields, exercising the Option::is_none path collision. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))] pub struct OptionRecord { pub choice: option::OptionRecordOption, #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, #[serde(flatten, default, skip_serializing_if = "Option::is_none")] pub extra_data: Option>>, } /// A locally-defined type named Option, colliding with std::option::Option. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)] #[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))] pub struct OptionRecordOption { pub key: S, pub value: S, #[serde(flatten, default, skip_serializing_if = "Option::is_none")] pub extra_data: Option>>, } impl LexiconSchema for OptionRecord { fn nsid() -> &'static str { "test.collision.option" } fn def_name() -> &'static str { "main" } fn lexicon_doc() -> LexiconDoc<'static> { lexicon_doc_test_collision_option() } fn validate(&self) -> Result<(), ConstraintError> { if let Some(ref value) = self.description { #[allow(unused_comparisons)] if ::len(value.as_ref()) > 500usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("description"), max: 500usize, actual: ::len(value.as_ref()), }); } } Ok(()) } } impl LexiconSchema for OptionRecordOption { fn nsid() -> &'static str { "test.collision.option" } fn def_name() -> &'static str { "option" } fn lexicon_doc() -> LexiconDoc<'static> { lexicon_doc_test_collision_option() } fn validate(&self) -> Result<(), ConstraintError> { { let value = &self.key; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 100usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("key"), max: 100usize, actual: ::len(value.as_ref()), }); } } { let value = &self.value; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 500usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("value"), max: 500usize, actual: ::len(value.as_ref()), }); } } Ok(()) } } pub mod option_record_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 Choice; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type Choice = Unset; } ///State transition - sets the `choice` field to Set pub struct SetChoice(PhantomData St>); impl sealed::Sealed for SetChoice {} impl State for SetChoice { type Choice = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `choice` field pub struct choice(()); } } /// Builder for constructing an instance of this type. pub struct OptionRecordBuilder { _state: PhantomData St>, _fields: (Option>, Option), _type: PhantomData S>, } impl OptionRecord { /// Create a new builder for this type. pub fn new() -> OptionRecordBuilder { OptionRecordBuilder::new() } } impl OptionRecordBuilder { /// Create a new builder with all fields unset. pub fn new() -> Self { OptionRecordBuilder { _state: PhantomData, _fields: (None, None), _type: PhantomData, } } } impl OptionRecordBuilder where St: option_record_state::State, St::Choice: option_record_state::IsUnset, { /// Set the `choice` field (required) pub fn choice( mut self, value: impl Into>, ) -> OptionRecordBuilder> { self._fields.0 = Option::Some(value.into()); OptionRecordBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl OptionRecordBuilder { /// Set the `description` field (optional) pub fn description(mut self, value: impl Into>) -> Self { self._fields.1 = value.into(); self } /// Set the `description` field to an Option value (optional) pub fn maybe_description(mut self, value: Option) -> Self { self._fields.1 = value; self } } impl OptionRecordBuilder where St: option_record_state::State, St::Choice: option_record_state::IsSet, { /// Build the final struct. pub fn build(self) -> OptionRecord { OptionRecord { choice: self._fields.0.unwrap(), description: self._fields.1, extra_data: Default::default(), } } /// Build the final struct with custom extra_data. pub fn build_with_data( self, extra_data: BTreeMap>, ) -> OptionRecord { OptionRecord { choice: self._fields.0.unwrap(), description: self._fields.1, extra_data: Some(extra_data), } } } fn lexicon_doc_test_collision_option() -> LexiconDoc<'static> { #[allow(unused_imports)] use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType}; use jacquard_lexicon::lexicon::*; use alloc::collections::BTreeMap; LexiconDoc { lexicon: Lexicon::Lexicon1, id: CowStr::new_static("test.collision.option"), defs: { let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("main"), LexUserType::Object(LexObject { description: Some( CowStr::new_static( "An object with optional fields, exercising the Option::is_none path collision.", ), ), required: Some(vec![SmolStr::new_static("choice")]), properties: { #[allow(unused_mut)] let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("choice"), LexObjectProperty::Ref(LexRef { r#ref: CowStr::new_static("#option"), ..Default::default() }), ); map.insert( SmolStr::new_static("description"), LexObjectProperty::String(LexString { max_length: Some(500usize), ..Default::default() }), ); map }, ..Default::default() }), ); map.insert( SmolStr::new_static("option"), LexUserType::Object(LexObject { description: Some( CowStr::new_static( "A locally-defined type named Option, colliding with std::option::Option.", ), ), required: Some( vec![SmolStr::new_static("key"), SmolStr::new_static("value")], ), properties: { #[allow(unused_mut)] let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("key"), LexObjectProperty::String(LexString { max_length: Some(100usize), ..Default::default() }), ); map.insert( SmolStr::new_static("value"), LexObjectProperty::String(LexString { max_length: Some(500usize), ..Default::default() }), ); map }, ..Default::default() }), ); map }, ..Default::default() } }