// @generated by jacquard-lexicon. DO NOT EDIT. // // Lexicon: dev.tsunagite.game // // 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::{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::blob::BlobRef; use jacquard_common::types::collection::{Collection, RecordError}; use jacquard_common::types::string::{AtUri, Cid, RecordKey, Rkey}; use jacquard_common::types::uri::{RecordUri, UriError}; use jacquard_common::types::value::Data; use jacquard_common::xrpc::XrpcResp; use jacquard_derive::{IntoStatic, lexicon, open_union}; use jacquard_lexicon::lexicon::LexiconDoc; use jacquard_lexicon::schema::LexiconSchema; use crate::dev_tsunagite::game; use crate::dev_tsunagite::types::Indexable; #[allow(unused_imports)] use jacquard_lexicon::validation::{ConstraintError, ValidationPath}; use serde::{Deserialize, Serialize}; /// A closed set of indexable named values. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde( rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr") )] pub struct Enum { /// The internal ID of this component, limited to the RecordKey characterset. pub id: RecordKey>, /// The human-readable name of this component in UI. pub name: Data, /// The allowed values for this enum to take. pub values: Vec>, #[serde( flatten, default, deserialize_with = "deserialize_enum_extra_data", skip_serializing_if = "Option::is_none" )] pub extra_data: Option>>, } /// A record describing a game hosting leaderboards via Tsunagite. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde( rename_all = "camelCase", rename = "dev.tsunagite.game", tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr") )] pub struct Game { /// The default component for leaderboard sorting. pub default_component: RecordKey>, /// An array of usable input methods for the game. Optional if the game only has one input method or doesn't separate leaderboards by method. #[serde(skip_serializing_if = "Option::is_none")] pub input_methods: Option>>, /// The obtainable judgments during gameplay. pub judgments: Vec>, /// The logo of the game, for display in UI. #[serde(skip_serializing_if = "Option::is_none")] pub logo: Option>, /// An array of playable game modes with different gameplay configurations. Optional if the game only has one mode. #[serde(skip_serializing_if = "Option::is_none")] pub modes: Option>>, /// The human-readable name of the game, for display in UI. pub name: Data, /// All the components of a score in the game, including grades, lamps, EX score, and whatever other constructs are used. pub score_components: Vec>, #[serde( flatten, default, deserialize_with = "deserialize_game_extra_data", skip_serializing_if = "Option::is_none" )] pub extra_data: Option>>, } /// Can be tokens or raw strings. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum GameInputMethods { DevTsunagiteKeyboard, DevTsunagiteGamepad, Other(S), } impl GameInputMethods { pub fn as_str(&self) -> &str { match self { Self::DevTsunagiteKeyboard => "dev.tsunagite.keyboard", Self::DevTsunagiteGamepad => "dev.tsunagite.gamepad", Self::Other(s) => s.as_ref(), } } /// Construct from a string-like value, matching known values. pub fn from_value(s: S) -> Self { match s.as_ref() { "dev.tsunagite.keyboard" => Self::DevTsunagiteKeyboard, "dev.tsunagite.gamepad" => Self::DevTsunagiteGamepad, _ => Self::Other(s), } } } impl core::fmt::Display for GameInputMethods { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", self.as_str()) } } impl AsRef for GameInputMethods { fn as_ref(&self) -> &str { self.as_str() } } impl Serialize for GameInputMethods { fn serialize(&self, serializer: Ser) -> Result where Ser: serde::Serializer, { serializer.serialize_str(self.as_str()) } } impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for GameInputMethods { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { let s = S::deserialize(deserializer)?; Ok(Self::from_value(s)) } } impl Default for GameInputMethods { fn default() -> Self { Self::Other(Default::default()) } } impl jacquard_common::IntoStatic for GameInputMethods where S: BosStr + jacquard_common::IntoStatic, S::Output: BosStr, { type Output = GameInputMethods; fn into_static(self) -> Self::Output { match self { GameInputMethods::DevTsunagiteKeyboard => GameInputMethods::DevTsunagiteKeyboard, GameInputMethods::DevTsunagiteGamepad => GameInputMethods::DevTsunagiteGamepad, GameInputMethods::Other(v) => GameInputMethods::Other(v.into_static()), } } } /// Can be tokens or raw strings. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum GameModes { DevTsunagiteSingles, DevTsunagiteDoubles, Other(S), } impl GameModes { pub fn as_str(&self) -> &str { match self { Self::DevTsunagiteSingles => "dev.tsunagite.singles", Self::DevTsunagiteDoubles => "dev.tsunagite.doubles", Self::Other(s) => s.as_ref(), } } /// Construct from a string-like value, matching known values. pub fn from_value(s: S) -> Self { match s.as_ref() { "dev.tsunagite.singles" => Self::DevTsunagiteSingles, "dev.tsunagite.doubles" => Self::DevTsunagiteDoubles, _ => Self::Other(s), } } } impl core::fmt::Display for GameModes { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", self.as_str()) } } impl AsRef for GameModes { fn as_ref(&self) -> &str { self.as_str() } } impl Serialize for GameModes { fn serialize(&self, serializer: Ser) -> Result where Ser: serde::Serializer, { serializer.serialize_str(self.as_str()) } } impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for GameModes { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { let s = S::deserialize(deserializer)?; Ok(Self::from_value(s)) } } impl Default for GameModes { fn default() -> Self { Self::Other(Default::default()) } } impl jacquard_common::IntoStatic for GameModes where S: BosStr + jacquard_common::IntoStatic, S::Output: BosStr, { type Output = GameModes; fn into_static(self) -> Self::Output { match self { GameModes::DevTsunagiteSingles => GameModes::DevTsunagiteSingles, GameModes::DevTsunagiteDoubles => GameModes::DevTsunagiteDoubles, GameModes::Other(v) => GameModes::Other(v.into_static()), } } } #[open_union] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))] pub enum GameScoreComponentsItem { #[serde(rename = "dev.tsunagite.game#enum")] Enum(Box>), #[serde(rename = "dev.tsunagite.game#points")] Points(Box>), #[serde(rename = "dev.tsunagite.game#percentage")] Percentage(Box>), #[serde(rename = "dev.tsunagite.game#text")] Text(Box>), } /// Typed wrapper for GetRecord response with this collection's record type. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase")] pub struct GameGetRecordOutput { #[serde(skip_serializing_if = "Option::is_none")] pub cid: Option>, pub uri: AtUri, pub value: Game, } /// A percentage score with customizable precision. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde( rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr") )] pub struct Percentage { /// The internal ID of this component, limited to the RecordKey characterset. pub id: RecordKey>, /// The maximum allowed percentage for this score. Defaults to `100`. #[serde(default = "_default_percentage_maximum")] pub maximum: i64, /// The human-readable name of this component in UI. pub name: Data, /// The number of decimal places to include in the percentage. Defaults to `2`. #[serde(default = "_default_percentage_precision")] pub precision: i64, #[serde( flatten, default, deserialize_with = "deserialize_percentage_extra_data", skip_serializing_if = "Option::is_none" )] pub extra_data: Option>>, } /// An integer point score, with or without a cap. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde( rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr") )] pub struct Points { /// The internal ID of this component, limited to the RecordKey characterset. pub id: RecordKey>, /// The maximum allowed value for this score. #[serde(skip_serializing_if = "Option::is_none")] pub maximum: Option, /// The human-readable name of this component in UI. pub name: Data, #[serde( flatten, default, deserialize_with = "deserialize_points_extra_data", skip_serializing_if = "Option::is_none" )] pub extra_data: Option>>, } /// A fallback component for displaying arbitrary text. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde( rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr") )] pub struct Text { /// The internal ID of this component, limited to the RecordKey characterset. pub id: RecordKey>, /// The human-readable name of this component in UI. pub name: Data, #[serde( flatten, default, deserialize_with = "deserialize_text_extra_data", skip_serializing_if = "Option::is_none" )] pub extra_data: Option>>, } impl Game { pub fn uri(uri: S) -> Result, UriError> { RecordUri::try_from_uri(AtUri::new(uri)?) } } impl LexiconSchema for Enum { fn nsid() -> &'static str { "dev.tsunagite.game" } fn def_name() -> &'static str { "enum" } fn lexicon_doc() -> LexiconDoc<'static> { lexicon_doc_dev_tsunagite_game() } fn validate(&self) -> Result<(), ConstraintError> { { let value = &self.id; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 32usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("id"), max: 32usize, actual: ::len(value.as_ref()), }); } } { let value = &self.id; #[allow(unused_comparisons)] if ::len(value.as_ref()) < 1usize { return Err(ConstraintError::MinLength { path: ValidationPath::from_field("id"), min: 1usize, actual: ::len(value.as_ref()), }); } } Ok(()) } } /// Marker type for deserializing records from this collection. #[derive(Debug, Serialize, Deserialize)] pub struct GameRecord; impl XrpcResp for GameRecord { const NSID: &'static str = "dev.tsunagite.game"; const ENCODING: &'static str = "application/json"; type Output = GameGetRecordOutput; type Err = RecordError; } impl From> for Game { fn from(output: GameGetRecordOutput) -> Self { output.value } } impl Collection for Game { const NSID: &'static str = "dev.tsunagite.game"; type Record = GameRecord; } impl Collection for GameRecord { const NSID: &'static str = "dev.tsunagite.game"; type Record = GameRecord; } impl LexiconSchema for Game { fn nsid() -> &'static str { "dev.tsunagite.game" } fn def_name() -> &'static str { "main" } fn lexicon_doc() -> LexiconDoc<'static> { lexicon_doc_dev_tsunagite_game() } fn validate(&self) -> Result<(), ConstraintError> { if let Some(ref value) = self.logo { { let size = value.blob().size; if size > 8000000usize { return Err(ConstraintError::BlobTooLarge { path: ValidationPath::from_field("logo"), max: 8000000usize, actual: size, }); } } } if let Some(ref value) = self.logo { { let mime = value.blob().mime_type.as_str(); let accepted: &[&str] = &["image/png", "image/jpeg", "image/jxl", "image/webp"]; let matched = accepted.iter().any(|pattern| { if *pattern == "*/*" { true } else if pattern.ends_with("/*") { let prefix = &pattern[..pattern.len() - 2]; mime.starts_with(prefix) && mime.as_bytes().get(prefix.len()) == Some(&b'/') } else { mime == *pattern } }); if !matched { return Err(ConstraintError::BlobMimeTypeNotAccepted { path: ValidationPath::from_field("logo"), accepted: vec![ "image/png".to_string(), "image/jpeg".to_string(), "image/jxl".to_string(), "image/webp".to_string(), ], actual: mime.to_string(), }); } } } Ok(()) } } impl LexiconSchema for Percentage { fn nsid() -> &'static str { "dev.tsunagite.game" } fn def_name() -> &'static str { "percentage" } fn lexicon_doc() -> LexiconDoc<'static> { lexicon_doc_dev_tsunagite_game() } fn validate(&self) -> Result<(), ConstraintError> { { let value = &self.id; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 32usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("id"), max: 32usize, actual: ::len(value.as_ref()), }); } } { let value = &self.id; #[allow(unused_comparisons)] if ::len(value.as_ref()) < 1usize { return Err(ConstraintError::MinLength { path: ValidationPath::from_field("id"), min: 1usize, actual: ::len(value.as_ref()), }); } } Ok(()) } } impl LexiconSchema for Points { fn nsid() -> &'static str { "dev.tsunagite.game" } fn def_name() -> &'static str { "points" } fn lexicon_doc() -> LexiconDoc<'static> { lexicon_doc_dev_tsunagite_game() } fn validate(&self) -> Result<(), ConstraintError> { { let value = &self.id; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 32usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("id"), max: 32usize, actual: ::len(value.as_ref()), }); } } { let value = &self.id; #[allow(unused_comparisons)] if ::len(value.as_ref()) < 1usize { return Err(ConstraintError::MinLength { path: ValidationPath::from_field("id"), min: 1usize, actual: ::len(value.as_ref()), }); } } Ok(()) } } impl LexiconSchema for Text { fn nsid() -> &'static str { "dev.tsunagite.game" } fn def_name() -> &'static str { "text" } fn lexicon_doc() -> LexiconDoc<'static> { lexicon_doc_dev_tsunagite_game() } fn validate(&self) -> Result<(), ConstraintError> { { let value = &self.id; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 32usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("id"), max: 32usize, actual: ::len(value.as_ref()), }); } } { let value = &self.id; #[allow(unused_comparisons)] if ::len(value.as_ref()) < 1usize { return Err(ConstraintError::MinLength { path: ValidationPath::from_field("id"), min: 1usize, actual: ::len(value.as_ref()), }); } } Ok(()) } } fn deserialize_enum_extra_data<'de, S, D>( deserializer: D, ) -> Result>>, D::Error> where S: BosStr + serde::Deserialize<'de>, D: serde::Deserializer<'de>, { let data = >> as serde::Deserialize<'de>>::deserialize(deserializer)?; Ok(data.filter(|extra_data| !extra_data.is_empty())) } pub mod enum_state { pub use crate::builder_types::{IsSet, IsUnset, Set, Unset}; #[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 Id; type Name; type Values; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type Id = Unset; type Name = Unset; type Values = Unset; } ///State transition - sets the `id` field to Set pub struct SetId(PhantomData St>); impl sealed::Sealed for SetId {} impl State for SetId { type Id = Set; type Name = St::Name; type Values = St::Values; } ///State transition - sets the `name` field to Set pub struct SetName(PhantomData St>); impl sealed::Sealed for SetName {} impl State for SetName { type Id = St::Id; type Name = Set; type Values = St::Values; } ///State transition - sets the `values` field to Set pub struct SetValues(PhantomData St>); impl sealed::Sealed for SetValues {} impl State for SetValues { type Id = St::Id; type Name = St::Name; type Values = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `id` field pub struct id(()); ///Marker type for the `name` field pub struct name(()); ///Marker type for the `values` field pub struct values(()); } } /// Builder for constructing an instance of this type. pub struct EnumBuilder { _state: PhantomData St>, _fields: ( Option>>, Option>, Option>>, ), _type: PhantomData S>, } impl Enum { /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed pub fn new() -> EnumBuilder { EnumBuilder::new() } } impl Enum { /// Create a new builder for this type pub fn builder() -> EnumBuilder { EnumBuilder::builder() } } impl EnumBuilder { /// Create a new builder with all fields unset, using the default string type, if needed pub fn new() -> Self { EnumBuilder { _state: PhantomData, _fields: (None, None, None), _type: PhantomData, } } } impl EnumBuilder { /// Create a new builder with all fields unset pub fn builder() -> Self { EnumBuilder { _state: PhantomData, _fields: (None, None, None), _type: PhantomData, } } } impl EnumBuilder where St: enum_state::State, St::Id: enum_state::IsUnset, { /// Set the `id` field (required) pub fn id( mut self, value: impl Into>>, ) -> EnumBuilder, S> { self._fields.0 = Option::Some(value.into()); EnumBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl EnumBuilder where St: enum_state::State, St::Name: enum_state::IsUnset, { /// Set the `name` field (required) pub fn name(mut self, value: impl Into>) -> EnumBuilder, S> { self._fields.1 = Option::Some(value.into()); EnumBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl EnumBuilder where St: enum_state::State, St::Values: enum_state::IsUnset, { /// Set the `values` field (required) pub fn values( mut self, value: impl Into>>, ) -> EnumBuilder, S> { self._fields.2 = Option::Some(value.into()); EnumBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl EnumBuilder where St: enum_state::State, St::Id: enum_state::IsSet, St::Name: enum_state::IsSet, St::Values: enum_state::IsSet, { /// Build the final struct. pub fn build(self) -> Enum { Enum { id: self._fields.0.unwrap(), name: self._fields.1.unwrap(), values: self._fields.2.unwrap(), extra_data: Default::default(), } } /// Build the final struct with custom extra_data. pub fn build_with_data(self, extra_data: BTreeMap>) -> Enum { Enum { id: self._fields.0.unwrap(), name: self._fields.1.unwrap(), values: self._fields.2.unwrap(), extra_data: Some(extra_data), } } } fn lexicon_doc_dev_tsunagite_game() -> 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("dev.tsunagite.game"), defs: { let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("enum"), LexUserType::Object(LexObject { description: Some( CowStr::new_static("A closed set of indexable named values."), ), required: Some( vec![ SmolStr::new_static("name"), SmolStr::new_static("id"), SmolStr::new_static("values") ], ), properties: { #[allow(unused_mut)] let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("id"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static( "The internal ID of this component, limited to the RecordKey characterset.", ), ), format: Some(LexStringFormat::RecordKey), min_length: Some(1usize), max_length: Some(32usize), ..Default::default() }), ); map.insert( SmolStr::new_static("name"), LexObjectProperty::Ref(LexRef { r#ref: CowStr::new_static("dev.tsunagite.translatable"), ..Default::default() }), ); map.insert( SmolStr::new_static("values"), LexObjectProperty::Array(LexArray { description: Some( CowStr::new_static( "The allowed values for this enum to take.", ), ), items: LexArrayItem::Ref(LexRef { r#ref: CowStr::new_static("dev.tsunagite.types#indexable"), ..Default::default() }), ..Default::default() }), ); map }, ..Default::default() }), ); map.insert( SmolStr::new_static("main"), LexUserType::Record(LexRecord { description: Some( CowStr::new_static( "A record describing a game hosting leaderboards via Tsunagite.", ), ), key: Some(CowStr::new_static("any")), record: LexRecordRecord::Object(LexObject { required: Some( vec![ SmolStr::new_static("name"), SmolStr::new_static("judgments"), SmolStr::new_static("scoreComponents"), SmolStr::new_static("defaultComponent") ], ), properties: { #[allow(unused_mut)] let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("defaultComponent"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static( "The default component for leaderboard sorting.", ), ), format: Some(LexStringFormat::RecordKey), ..Default::default() }), ); map.insert( SmolStr::new_static("inputMethods"), LexObjectProperty::Array(LexArray { description: Some( CowStr::new_static( "An array of usable input methods for the game. Optional if the game only has one input method or doesn't separate leaderboards by method.", ), ), items: LexArrayItem::String(LexString { description: Some( CowStr::new_static("Can be tokens or raw strings."), ), ..Default::default() }), ..Default::default() }), ); map.insert( SmolStr::new_static("judgments"), LexObjectProperty::Array(LexArray { description: Some( CowStr::new_static( "The obtainable judgments during gameplay.", ), ), items: LexArrayItem::Ref(LexRef { r#ref: CowStr::new_static("dev.tsunagite.types#indexable"), ..Default::default() }), ..Default::default() }), ); map.insert( SmolStr::new_static("logo"), LexObjectProperty::Blob(LexBlob { ..Default::default() }), ); map.insert( SmolStr::new_static("modes"), LexObjectProperty::Array(LexArray { description: Some( CowStr::new_static( "An array of playable game modes with different gameplay configurations. Optional if the game only has one mode.", ), ), items: LexArrayItem::String(LexString { description: Some( CowStr::new_static("Can be tokens or raw strings."), ), ..Default::default() }), ..Default::default() }), ); map.insert( SmolStr::new_static("name"), LexObjectProperty::Ref(LexRef { r#ref: CowStr::new_static("dev.tsunagite.translatable"), ..Default::default() }), ); map.insert( SmolStr::new_static("scoreComponents"), LexObjectProperty::Array(LexArray { description: Some( CowStr::new_static( "All the components of a score in the game, including grades, lamps, EX score, and whatever other constructs are used.", ), ), items: LexArrayItem::Union(LexRefUnion { refs: vec![ CowStr::new_static("#enum"), CowStr::new_static("#points"), CowStr::new_static("#percentage"), CowStr::new_static("#text") ], ..Default::default() }), ..Default::default() }), ); map }, ..Default::default() }), ..Default::default() }), ); map.insert( SmolStr::new_static("percentage"), LexUserType::Object(LexObject { description: Some( CowStr::new_static( "A percentage score with customizable precision.", ), ), required: Some( vec![ SmolStr::new_static("name"), SmolStr::new_static("id"), SmolStr::new_static("maximum"), SmolStr::new_static("precision") ], ), properties: { #[allow(unused_mut)] let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("id"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static( "The internal ID of this component, limited to the RecordKey characterset.", ), ), format: Some(LexStringFormat::RecordKey), min_length: Some(1usize), max_length: Some(32usize), ..Default::default() }), ); map.insert( SmolStr::new_static("maximum"), LexObjectProperty::Integer(LexInteger { ..Default::default() }), ); map.insert( SmolStr::new_static("name"), LexObjectProperty::Ref(LexRef { r#ref: CowStr::new_static("dev.tsunagite.translatable"), ..Default::default() }), ); map.insert( SmolStr::new_static("precision"), LexObjectProperty::Integer(LexInteger { ..Default::default() }), ); map }, ..Default::default() }), ); map.insert( SmolStr::new_static("points"), LexUserType::Object(LexObject { description: Some( CowStr::new_static( "An integer point score, with or without a cap.", ), ), required: Some( vec![SmolStr::new_static("name"), SmolStr::new_static("id")], ), properties: { #[allow(unused_mut)] let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("id"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static( "The internal ID of this component, limited to the RecordKey characterset.", ), ), format: Some(LexStringFormat::RecordKey), min_length: Some(1usize), max_length: Some(32usize), ..Default::default() }), ); map.insert( SmolStr::new_static("maximum"), LexObjectProperty::Integer(LexInteger { ..Default::default() }), ); map.insert( SmolStr::new_static("name"), LexObjectProperty::Ref(LexRef { r#ref: CowStr::new_static("dev.tsunagite.translatable"), ..Default::default() }), ); map }, ..Default::default() }), ); map.insert( SmolStr::new_static("text"), LexUserType::Object(LexObject { description: Some( CowStr::new_static( "A fallback component for displaying arbitrary text.", ), ), required: Some( vec![SmolStr::new_static("name"), SmolStr::new_static("id")], ), properties: { #[allow(unused_mut)] let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("id"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static( "The internal ID of this component, limited to the RecordKey characterset.", ), ), format: Some(LexStringFormat::RecordKey), min_length: Some(1usize), max_length: Some(32usize), ..Default::default() }), ); map.insert( SmolStr::new_static("name"), LexObjectProperty::Ref(LexRef { r#ref: CowStr::new_static("dev.tsunagite.translatable"), ..Default::default() }), ); map }, ..Default::default() }), ); map }, ..Default::default() } } fn deserialize_game_extra_data<'de, S, D>( deserializer: D, ) -> Result>>, D::Error> where S: BosStr + serde::Deserialize<'de>, D: serde::Deserializer<'de>, { let mut data = >> as serde::Deserialize<'de>>::deserialize(deserializer)?; if let Some(extra_data) = &mut data { extra_data.remove("$type"); if extra_data.is_empty() { data = None; } } Ok(data) } pub mod game_state { pub use crate::builder_types::{IsSet, IsUnset, Set, Unset}; #[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 DefaultComponent; type Judgments; type Name; type ScoreComponents; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type DefaultComponent = Unset; type Judgments = Unset; type Name = Unset; type ScoreComponents = Unset; } ///State transition - sets the `default_component` field to Set pub struct SetDefaultComponent(PhantomData St>); impl sealed::Sealed for SetDefaultComponent {} impl State for SetDefaultComponent { type DefaultComponent = Set; type Judgments = St::Judgments; type Name = St::Name; type ScoreComponents = St::ScoreComponents; } ///State transition - sets the `judgments` field to Set pub struct SetJudgments(PhantomData St>); impl sealed::Sealed for SetJudgments {} impl State for SetJudgments { type DefaultComponent = St::DefaultComponent; type Judgments = Set; type Name = St::Name; type ScoreComponents = St::ScoreComponents; } ///State transition - sets the `name` field to Set pub struct SetName(PhantomData St>); impl sealed::Sealed for SetName {} impl State for SetName { type DefaultComponent = St::DefaultComponent; type Judgments = St::Judgments; type Name = Set; type ScoreComponents = St::ScoreComponents; } ///State transition - sets the `score_components` field to Set pub struct SetScoreComponents(PhantomData St>); impl sealed::Sealed for SetScoreComponents {} impl State for SetScoreComponents { type DefaultComponent = St::DefaultComponent; type Judgments = St::Judgments; type Name = St::Name; type ScoreComponents = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `default_component` field pub struct default_component(()); ///Marker type for the `judgments` field pub struct judgments(()); ///Marker type for the `name` field pub struct name(()); ///Marker type for the `score_components` field pub struct score_components(()); } } /// Builder for constructing an instance of this type. pub struct GameBuilder { _state: PhantomData St>, _fields: ( Option>>, Option>>, Option>>, Option>, Option>>, Option>, Option>>, ), _type: PhantomData S>, } impl Game { /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed pub fn new() -> GameBuilder { GameBuilder::new() } } impl Game { /// Create a new builder for this type pub fn builder() -> GameBuilder { GameBuilder::builder() } } impl GameBuilder { /// Create a new builder with all fields unset, using the default string type, if needed pub fn new() -> Self { GameBuilder { _state: PhantomData, _fields: (None, None, None, None, None, None, None), _type: PhantomData, } } } impl GameBuilder { /// Create a new builder with all fields unset pub fn builder() -> Self { GameBuilder { _state: PhantomData, _fields: (None, None, None, None, None, None, None), _type: PhantomData, } } } impl GameBuilder where St: game_state::State, St::DefaultComponent: game_state::IsUnset, { /// Set the `defaultComponent` field (required) pub fn default_component( mut self, value: impl Into>>, ) -> GameBuilder, S> { self._fields.0 = Option::Some(value.into()); GameBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl GameBuilder { /// Set the `inputMethods` field (optional) pub fn input_methods(mut self, value: impl Into>>>) -> Self { self._fields.1 = value.into(); self } /// Set the `inputMethods` field to an Option value (optional) pub fn maybe_input_methods(mut self, value: Option>>) -> Self { self._fields.1 = value; self } } impl GameBuilder where St: game_state::State, St::Judgments: game_state::IsUnset, { /// Set the `judgments` field (required) pub fn judgments( mut self, value: impl Into>>, ) -> GameBuilder, S> { self._fields.2 = Option::Some(value.into()); GameBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl GameBuilder { /// Set the `logo` field (optional) pub fn logo(mut self, value: impl Into>>) -> Self { self._fields.3 = value.into(); self } /// Set the `logo` field to an Option value (optional) pub fn maybe_logo(mut self, value: Option>) -> Self { self._fields.3 = value; self } } impl GameBuilder { /// Set the `modes` field (optional) pub fn modes(mut self, value: impl Into>>>) -> Self { self._fields.4 = value.into(); self } /// Set the `modes` field to an Option value (optional) pub fn maybe_modes(mut self, value: Option>>) -> Self { self._fields.4 = value; self } } impl GameBuilder where St: game_state::State, St::Name: game_state::IsUnset, { /// Set the `name` field (required) pub fn name(mut self, value: impl Into>) -> GameBuilder, S> { self._fields.5 = Option::Some(value.into()); GameBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl GameBuilder where St: game_state::State, St::ScoreComponents: game_state::IsUnset, { /// Set the `scoreComponents` field (required) pub fn score_components( mut self, value: impl Into>>, ) -> GameBuilder, S> { self._fields.6 = Option::Some(value.into()); GameBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl GameBuilder where St: game_state::State, St::DefaultComponent: game_state::IsSet, St::Judgments: game_state::IsSet, St::Name: game_state::IsSet, St::ScoreComponents: game_state::IsSet, { /// Build the final struct. pub fn build(self) -> Game { Game { default_component: self._fields.0.unwrap(), input_methods: self._fields.1, judgments: self._fields.2.unwrap(), logo: self._fields.3, modes: self._fields.4, name: self._fields.5.unwrap(), score_components: self._fields.6.unwrap(), extra_data: Default::default(), } } /// Build the final struct with custom extra_data. pub fn build_with_data(self, extra_data: BTreeMap>) -> Game { Game { default_component: self._fields.0.unwrap(), input_methods: self._fields.1, judgments: self._fields.2.unwrap(), logo: self._fields.3, modes: self._fields.4, name: self._fields.5.unwrap(), score_components: self._fields.6.unwrap(), extra_data: Some(extra_data), } } } fn deserialize_percentage_extra_data<'de, S, D>( deserializer: D, ) -> Result>>, D::Error> where S: BosStr + serde::Deserialize<'de>, D: serde::Deserializer<'de>, { let data = >> as serde::Deserialize<'de>>::deserialize(deserializer)?; Ok(data.filter(|extra_data| !extra_data.is_empty())) } fn _default_percentage_maximum() -> i64 { 100i64 } fn _default_percentage_precision() -> i64 { 2i64 } pub mod percentage_state { pub use crate::builder_types::{IsSet, IsUnset, Set, Unset}; #[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 Id; type Maximum; type Name; type Precision; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type Id = Unset; type Maximum = Unset; type Name = Unset; type Precision = Unset; } ///State transition - sets the `id` field to Set pub struct SetId(PhantomData St>); impl sealed::Sealed for SetId {} impl State for SetId { type Id = Set; type Maximum = St::Maximum; type Name = St::Name; type Precision = St::Precision; } ///State transition - sets the `maximum` field to Set pub struct SetMaximum(PhantomData St>); impl sealed::Sealed for SetMaximum {} impl State for SetMaximum { type Id = St::Id; type Maximum = Set; type Name = St::Name; type Precision = St::Precision; } ///State transition - sets the `name` field to Set pub struct SetName(PhantomData St>); impl sealed::Sealed for SetName {} impl State for SetName { type Id = St::Id; type Maximum = St::Maximum; type Name = Set; type Precision = St::Precision; } ///State transition - sets the `precision` field to Set pub struct SetPrecision(PhantomData St>); impl sealed::Sealed for SetPrecision {} impl State for SetPrecision { type Id = St::Id; type Maximum = St::Maximum; type Name = St::Name; type Precision = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `id` field pub struct id(()); ///Marker type for the `maximum` field pub struct maximum(()); ///Marker type for the `name` field pub struct name(()); ///Marker type for the `precision` field pub struct precision(()); } } /// Builder for constructing an instance of this type. pub struct PercentageBuilder { _state: PhantomData St>, _fields: ( Option>>, Option, Option>, Option, ), _type: PhantomData S>, } impl Percentage { /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed pub fn new() -> PercentageBuilder { PercentageBuilder::new() } } impl Percentage { /// Create a new builder for this type pub fn builder() -> PercentageBuilder { PercentageBuilder::builder() } } impl PercentageBuilder { /// Create a new builder with all fields unset, using the default string type, if needed pub fn new() -> Self { PercentageBuilder { _state: PhantomData, _fields: (None, None, None, None), _type: PhantomData, } } } impl PercentageBuilder { /// Create a new builder with all fields unset pub fn builder() -> Self { PercentageBuilder { _state: PhantomData, _fields: (None, None, None, None), _type: PhantomData, } } } impl PercentageBuilder where St: percentage_state::State, St::Id: percentage_state::IsUnset, { /// Set the `id` field (required) pub fn id( mut self, value: impl Into>>, ) -> PercentageBuilder, S> { self._fields.0 = Option::Some(value.into()); PercentageBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl PercentageBuilder where St: percentage_state::State, St::Maximum: percentage_state::IsUnset, { /// Set the `maximum` field (required) pub fn maximum( mut self, value: impl Into, ) -> PercentageBuilder, S> { self._fields.1 = Option::Some(value.into()); PercentageBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl PercentageBuilder where St: percentage_state::State, St::Name: percentage_state::IsUnset, { /// Set the `name` field (required) pub fn name( mut self, value: impl Into>, ) -> PercentageBuilder, S> { self._fields.2 = Option::Some(value.into()); PercentageBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl PercentageBuilder where St: percentage_state::State, St::Precision: percentage_state::IsUnset, { /// Set the `precision` field (required) pub fn precision( mut self, value: impl Into, ) -> PercentageBuilder, S> { self._fields.3 = Option::Some(value.into()); PercentageBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl PercentageBuilder where St: percentage_state::State, St::Id: percentage_state::IsSet, St::Maximum: percentage_state::IsSet, St::Name: percentage_state::IsSet, St::Precision: percentage_state::IsSet, { /// Build the final struct. pub fn build(self) -> Percentage { Percentage { id: self._fields.0.unwrap(), maximum: self._fields.1.unwrap(), name: self._fields.2.unwrap(), precision: self._fields.3.unwrap(), extra_data: Default::default(), } } /// Build the final struct with custom extra_data. pub fn build_with_data(self, extra_data: BTreeMap>) -> Percentage { Percentage { id: self._fields.0.unwrap(), maximum: self._fields.1.unwrap(), name: self._fields.2.unwrap(), precision: self._fields.3.unwrap(), extra_data: Some(extra_data), } } } fn deserialize_points_extra_data<'de, S, D>( deserializer: D, ) -> Result>>, D::Error> where S: BosStr + serde::Deserialize<'de>, D: serde::Deserializer<'de>, { let data = >> as serde::Deserialize<'de>>::deserialize(deserializer)?; Ok(data.filter(|extra_data| !extra_data.is_empty())) } pub mod points_state { pub use crate::builder_types::{IsSet, IsUnset, Set, Unset}; #[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 Id; type Name; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type Id = Unset; type Name = Unset; } ///State transition - sets the `id` field to Set pub struct SetId(PhantomData St>); impl sealed::Sealed for SetId {} impl State for SetId { type Id = Set; type Name = St::Name; } ///State transition - sets the `name` field to Set pub struct SetName(PhantomData St>); impl sealed::Sealed for SetName {} impl State for SetName { type Id = St::Id; type Name = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `id` field pub struct id(()); ///Marker type for the `name` field pub struct name(()); } } /// Builder for constructing an instance of this type. pub struct PointsBuilder { _state: PhantomData St>, _fields: (Option>>, Option, Option>), _type: PhantomData S>, } impl Points { /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed pub fn new() -> PointsBuilder { PointsBuilder::new() } } impl Points { /// Create a new builder for this type pub fn builder() -> PointsBuilder { PointsBuilder::builder() } } impl PointsBuilder { /// Create a new builder with all fields unset, using the default string type, if needed pub fn new() -> Self { PointsBuilder { _state: PhantomData, _fields: (None, None, None), _type: PhantomData, } } } impl PointsBuilder { /// Create a new builder with all fields unset pub fn builder() -> Self { PointsBuilder { _state: PhantomData, _fields: (None, None, None), _type: PhantomData, } } } impl PointsBuilder where St: points_state::State, St::Id: points_state::IsUnset, { /// Set the `id` field (required) pub fn id( mut self, value: impl Into>>, ) -> PointsBuilder, S> { self._fields.0 = Option::Some(value.into()); PointsBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl PointsBuilder { /// Set the `maximum` field (optional) pub fn maximum(mut self, value: impl Into>) -> Self { self._fields.1 = value.into(); self } /// Set the `maximum` field to an Option value (optional) pub fn maybe_maximum(mut self, value: Option) -> Self { self._fields.1 = value; self } } impl PointsBuilder where St: points_state::State, St::Name: points_state::IsUnset, { /// Set the `name` field (required) pub fn name( mut self, value: impl Into>, ) -> PointsBuilder, S> { self._fields.2 = Option::Some(value.into()); PointsBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl PointsBuilder where St: points_state::State, St::Id: points_state::IsSet, St::Name: points_state::IsSet, { /// Build the final struct. pub fn build(self) -> Points { Points { id: self._fields.0.unwrap(), maximum: self._fields.1, name: self._fields.2.unwrap(), extra_data: Default::default(), } } /// Build the final struct with custom extra_data. pub fn build_with_data(self, extra_data: BTreeMap>) -> Points { Points { id: self._fields.0.unwrap(), maximum: self._fields.1, name: self._fields.2.unwrap(), extra_data: Some(extra_data), } } } fn deserialize_text_extra_data<'de, S, D>( deserializer: D, ) -> Result>>, D::Error> where S: BosStr + serde::Deserialize<'de>, D: serde::Deserializer<'de>, { let data = >> as serde::Deserialize<'de>>::deserialize(deserializer)?; Ok(data.filter(|extra_data| !extra_data.is_empty())) } pub mod text_state { pub use crate::builder_types::{IsSet, IsUnset, Set, Unset}; #[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 Id; type Name; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type Id = Unset; type Name = Unset; } ///State transition - sets the `id` field to Set pub struct SetId(PhantomData St>); impl sealed::Sealed for SetId {} impl State for SetId { type Id = Set; type Name = St::Name; } ///State transition - sets the `name` field to Set pub struct SetName(PhantomData St>); impl sealed::Sealed for SetName {} impl State for SetName { type Id = St::Id; type Name = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `id` field pub struct id(()); ///Marker type for the `name` field pub struct name(()); } } /// Builder for constructing an instance of this type. pub struct TextBuilder { _state: PhantomData St>, _fields: (Option>>, Option>), _type: PhantomData S>, } impl Text { /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed pub fn new() -> TextBuilder { TextBuilder::new() } } impl Text { /// Create a new builder for this type pub fn builder() -> TextBuilder { TextBuilder::builder() } } impl TextBuilder { /// Create a new builder with all fields unset, using the default string type, if needed pub fn new() -> Self { TextBuilder { _state: PhantomData, _fields: (None, None), _type: PhantomData, } } } impl TextBuilder { /// Create a new builder with all fields unset pub fn builder() -> Self { TextBuilder { _state: PhantomData, _fields: (None, None), _type: PhantomData, } } } impl TextBuilder where St: text_state::State, St::Id: text_state::IsUnset, { /// Set the `id` field (required) pub fn id( mut self, value: impl Into>>, ) -> TextBuilder, S> { self._fields.0 = Option::Some(value.into()); TextBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl TextBuilder where St: text_state::State, St::Name: text_state::IsUnset, { /// Set the `name` field (required) pub fn name(mut self, value: impl Into>) -> TextBuilder, S> { self._fields.1 = Option::Some(value.into()); TextBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl TextBuilder where St: text_state::State, St::Id: text_state::IsSet, St::Name: text_state::IsSet, { /// Build the final struct. pub fn build(self) -> Text { Text { id: self._fields.0.unwrap(), name: self._fields.1.unwrap(), extra_data: Default::default(), } } /// Build the final struct with custom extra_data. pub fn build_with_data(self, extra_data: BTreeMap>) -> Text { Text { id: self._fields.0.unwrap(), name: self._fields.1.unwrap(), extra_data: Some(extra_data), } } }