// @generated by jacquard-lexicon. DO NOT EDIT. // // Lexicon: app.offprint.block.imageCarousel // // 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; #[allow(unused_imports)] use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation; use jacquard_derive::{IntoStatic, lexicon}; 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::app_offprint::block::image_grid::GridImage; #[lexicon] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase")] pub struct ImageCarousel<'a> { ///Auto-advance slides Defaults to `false`. #[serde(skip_serializing_if = "Option::is_none")] #[serde(default = "_default_image_carousel_autoplay")] pub autoplay: Option, ///Carousel caption #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub caption: Option>, ///Array of images in the carousel (2-6) #[serde(borrow)] pub images: Vec>, ///Milliseconds between slides Defaults to `3000`. #[serde(skip_serializing_if = "Option::is_none")] #[serde(default = "_default_image_carousel_interval")] pub interval: Option, } impl<'a> LexiconSchema for ImageCarousel<'a> { fn nsid() -> &'static str { "app.offprint.block.imageCarousel" } fn def_name() -> &'static str { "main" } fn lexicon_doc() -> LexiconDoc<'static> { lexicon_doc_app_offprint_block_imageCarousel() } fn validate(&self) -> Result<(), ConstraintError> { { let value = &self.images; #[allow(unused_comparisons)] if value.len() > 6usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("images"), max: 6usize, actual: value.len(), }); } } { let value = &self.images; #[allow(unused_comparisons)] if value.len() < 2usize { return Err(ConstraintError::MinLength { path: ValidationPath::from_field("images"), min: 2usize, actual: value.len(), }); } } Ok(()) } } fn _default_image_carousel_autoplay() -> Option { Some(false) } fn _default_image_carousel_interval() -> Option { Some(3000i64) } pub mod image_carousel_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 Images; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type Images = Unset; } ///State transition - sets the `images` field to Set pub struct SetImages(PhantomData S>); impl sealed::Sealed for SetImages {} impl State for SetImages { type Images = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `images` field pub struct images(()); } } /// Builder for constructing an instance of this type pub struct ImageCarouselBuilder<'a, S: image_carousel_state::State> { _state: PhantomData S>, _fields: (Option, Option>, Option>>, Option), _lifetime: PhantomData<&'a ()>, } impl<'a> ImageCarousel<'a> { /// Create a new builder for this type pub fn new() -> ImageCarouselBuilder<'a, image_carousel_state::Empty> { ImageCarouselBuilder::new() } } impl<'a> ImageCarouselBuilder<'a, image_carousel_state::Empty> { /// Create a new builder with all fields unset pub fn new() -> Self { ImageCarouselBuilder { _state: PhantomData, _fields: (None, None, None, None), _lifetime: PhantomData, } } } impl<'a, S: image_carousel_state::State> ImageCarouselBuilder<'a, S> { /// Set the `autoplay` field (optional) pub fn autoplay(mut self, value: impl Into>) -> Self { self._fields.0 = value.into(); self } /// Set the `autoplay` field to an Option value (optional) pub fn maybe_autoplay(mut self, value: Option) -> Self { self._fields.0 = value; self } } impl<'a, S: image_carousel_state::State> ImageCarouselBuilder<'a, S> { /// Set the `caption` field (optional) pub fn caption(mut self, value: impl Into>>) -> Self { self._fields.1 = value.into(); self } /// Set the `caption` field to an Option value (optional) pub fn maybe_caption(mut self, value: Option>) -> Self { self._fields.1 = value; self } } impl<'a, S> ImageCarouselBuilder<'a, S> where S: image_carousel_state::State, S::Images: image_carousel_state::IsUnset, { /// Set the `images` field (required) pub fn images( mut self, value: impl Into>>, ) -> ImageCarouselBuilder<'a, image_carousel_state::SetImages> { self._fields.2 = Option::Some(value.into()); ImageCarouselBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S: image_carousel_state::State> ImageCarouselBuilder<'a, S> { /// Set the `interval` field (optional) pub fn interval(mut self, value: impl Into>) -> Self { self._fields.3 = value.into(); self } /// Set the `interval` field to an Option value (optional) pub fn maybe_interval(mut self, value: Option) -> Self { self._fields.3 = value; self } } impl<'a, S> ImageCarouselBuilder<'a, S> where S: image_carousel_state::State, S::Images: image_carousel_state::IsSet, { /// Build the final struct pub fn build(self) -> ImageCarousel<'a> { ImageCarousel { autoplay: self._fields.0.or_else(|| Some(false)), caption: self._fields.1, images: self._fields.2.unwrap(), interval: self._fields.3.or_else(|| Some(3000i64)), extra_data: Default::default(), } } /// Build the final struct with custom extra_data pub fn build_with_data( self, extra_data: BTreeMap< jacquard_common::deps::smol_str::SmolStr, jacquard_common::types::value::Data<'a>, >, ) -> ImageCarousel<'a> { ImageCarousel { autoplay: self._fields.0.or_else(|| Some(false)), caption: self._fields.1, images: self._fields.2.unwrap(), interval: self._fields.3.or_else(|| Some(3000i64)), extra_data: Some(extra_data), } } } fn lexicon_doc_app_offprint_block_imageCarousel() -> 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("app.offprint.block.imageCarousel"), defs: { let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("main"), LexUserType::Object(LexObject { required: Some(vec![SmolStr::new_static("images")]), properties: { #[allow(unused_mut)] let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("autoplay"), LexObjectProperty::Boolean(LexBoolean { ..Default::default() }), ); map.insert( SmolStr::new_static("caption"), LexObjectProperty::String(LexString { description: Some(CowStr::new_static("Carousel caption")), ..Default::default() }), ); map.insert( SmolStr::new_static("images"), LexObjectProperty::Array(LexArray { description: Some( CowStr::new_static("Array of images in the carousel (2-6)"), ), items: LexArrayItem::Ref(LexRef { r#ref: CowStr::new_static( "app.offprint.block.imageGrid#gridImage", ), ..Default::default() }), min_length: Some(2usize), max_length: Some(6usize), ..Default::default() }), ); map.insert( SmolStr::new_static("interval"), LexObjectProperty::Integer(LexInteger { ..Default::default() }), ); map }, ..Default::default() }), ); map }, ..Default::default() } }