// @generated by jacquard-lexicon. DO NOT EDIT. // // Lexicon: blue.2048.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::CowStr; #[allow(unused_imports)] use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation; use jacquard_common::types::collection::{Collection, RecordError}; use jacquard_common::types::string::{AtUri, Cid, Datetime}; use jacquard_common::types::uri::{RecordUri, UriError}; use jacquard_common::xrpc::XrpcResp; 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::blue__2048::SyncStatus; /// A declaration of an instance of a at://2048 game #[lexicon] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase")] pub struct Game<'a> { ///The player no longer has any moves left Defaults to `false`. #[serde(default = "_default_game_completed")] pub completed: bool, pub created_at: Datetime, ///The game's current score Defaults to `0`. #[serde(default = "_default_game_current_score")] pub current_score: i64, ///This is the recording of the game. Like chess notation, but for 2048 #[serde(borrow)] pub seeded_recording: CowStr<'a>, ///The sync status of this record with the users AT Protocol repo. #[serde(borrow)] pub sync_status: SyncStatus<'a>, ///The player has found a 2048 tile (they have won) Defaults to `false`. #[serde(default = "_default_game_won")] pub won: bool, } /// 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<'a> { #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub cid: Option>, #[serde(borrow)] pub uri: AtUri<'a>, #[serde(borrow)] pub value: Game<'a>, } impl<'a> Game<'a> { pub fn uri( uri: impl Into>, ) -> Result, UriError> { RecordUri::try_from_uri(AtUri::new_cow(uri.into())?) } } /// Marker type for deserializing records from this collection. #[derive(Debug, Serialize, Deserialize)] pub struct GameRecord; impl XrpcResp for GameRecord { const NSID: &'static str = "blue.2048.game"; const ENCODING: &'static str = "application/json"; type Output<'de> = GameGetRecordOutput<'de>; type Err<'de> = RecordError<'de>; } impl From> for Game<'_> { fn from(output: GameGetRecordOutput<'_>) -> Self { use jacquard_common::IntoStatic; output.value.into_static() } } impl Collection for Game<'_> { const NSID: &'static str = "blue.2048.game"; type Record = GameRecord; } impl Collection for GameRecord { const NSID: &'static str = "blue.2048.game"; type Record = GameRecord; } impl<'a> LexiconSchema for Game<'a> { fn nsid() -> &'static str { "blue.2048.game" } fn def_name() -> &'static str { "main" } fn lexicon_doc() -> LexiconDoc<'static> { lexicon_doc_blue_2048_game() } fn validate(&self) -> Result<(), ConstraintError> { Ok(()) } } fn _default_game_completed() -> bool { false } fn _default_game_current_score() -> i64 { 0i64 } fn _default_game_won() -> bool { false } pub mod game_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 Won; type Completed; type CurrentScore; type CreatedAt; type SeededRecording; type SyncStatus; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type Won = Unset; type Completed = Unset; type CurrentScore = Unset; type CreatedAt = Unset; type SeededRecording = Unset; type SyncStatus = Unset; } ///State transition - sets the `won` field to Set pub struct SetWon(PhantomData S>); impl sealed::Sealed for SetWon {} impl State for SetWon { type Won = Set; type Completed = S::Completed; type CurrentScore = S::CurrentScore; type CreatedAt = S::CreatedAt; type SeededRecording = S::SeededRecording; type SyncStatus = S::SyncStatus; } ///State transition - sets the `completed` field to Set pub struct SetCompleted(PhantomData S>); impl sealed::Sealed for SetCompleted {} impl State for SetCompleted { type Won = S::Won; type Completed = Set; type CurrentScore = S::CurrentScore; type CreatedAt = S::CreatedAt; type SeededRecording = S::SeededRecording; type SyncStatus = S::SyncStatus; } ///State transition - sets the `current_score` field to Set pub struct SetCurrentScore(PhantomData S>); impl sealed::Sealed for SetCurrentScore {} impl State for SetCurrentScore { type Won = S::Won; type Completed = S::Completed; type CurrentScore = Set; type CreatedAt = S::CreatedAt; type SeededRecording = S::SeededRecording; type SyncStatus = S::SyncStatus; } ///State transition - sets the `created_at` field to Set pub struct SetCreatedAt(PhantomData S>); impl sealed::Sealed for SetCreatedAt {} impl State for SetCreatedAt { type Won = S::Won; type Completed = S::Completed; type CurrentScore = S::CurrentScore; type CreatedAt = Set; type SeededRecording = S::SeededRecording; type SyncStatus = S::SyncStatus; } ///State transition - sets the `seeded_recording` field to Set pub struct SetSeededRecording(PhantomData S>); impl sealed::Sealed for SetSeededRecording {} impl State for SetSeededRecording { type Won = S::Won; type Completed = S::Completed; type CurrentScore = S::CurrentScore; type CreatedAt = S::CreatedAt; type SeededRecording = Set; type SyncStatus = S::SyncStatus; } ///State transition - sets the `sync_status` field to Set pub struct SetSyncStatus(PhantomData S>); impl sealed::Sealed for SetSyncStatus {} impl State for SetSyncStatus { type Won = S::Won; type Completed = S::Completed; type CurrentScore = S::CurrentScore; type CreatedAt = S::CreatedAt; type SeededRecording = S::SeededRecording; type SyncStatus = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `won` field pub struct won(()); ///Marker type for the `completed` field pub struct completed(()); ///Marker type for the `current_score` field pub struct current_score(()); ///Marker type for the `created_at` field pub struct created_at(()); ///Marker type for the `seeded_recording` field pub struct seeded_recording(()); ///Marker type for the `sync_status` field pub struct sync_status(()); } } /// Builder for constructing an instance of this type pub struct GameBuilder<'a, S: game_state::State> { _state: PhantomData S>, _fields: ( Option, Option, Option, Option>, Option>, Option, ), _lifetime: PhantomData<&'a ()>, } impl<'a> Game<'a> { /// Create a new builder for this type pub fn new() -> GameBuilder<'a, game_state::Empty> { GameBuilder::new() } } impl<'a> GameBuilder<'a, game_state::Empty> { /// Create a new builder with all fields unset pub fn new() -> Self { GameBuilder { _state: PhantomData, _fields: (None, None, None, None, None, None), _lifetime: PhantomData, } } } impl<'a, S> GameBuilder<'a, S> where S: game_state::State, S::Completed: game_state::IsUnset, { /// Set the `completed` field (required) pub fn completed( mut self, value: impl Into, ) -> GameBuilder<'a, game_state::SetCompleted> { self._fields.0 = Option::Some(value.into()); GameBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S> GameBuilder<'a, S> where S: game_state::State, S::CreatedAt: game_state::IsUnset, { /// Set the `createdAt` field (required) pub fn created_at( mut self, value: impl Into, ) -> GameBuilder<'a, game_state::SetCreatedAt> { self._fields.1 = Option::Some(value.into()); GameBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S> GameBuilder<'a, S> where S: game_state::State, S::CurrentScore: game_state::IsUnset, { /// Set the `currentScore` field (required) pub fn current_score( mut self, value: impl Into, ) -> GameBuilder<'a, game_state::SetCurrentScore> { self._fields.2 = Option::Some(value.into()); GameBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S> GameBuilder<'a, S> where S: game_state::State, S::SeededRecording: game_state::IsUnset, { /// Set the `seededRecording` field (required) pub fn seeded_recording( mut self, value: impl Into>, ) -> GameBuilder<'a, game_state::SetSeededRecording> { self._fields.3 = Option::Some(value.into()); GameBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S> GameBuilder<'a, S> where S: game_state::State, S::SyncStatus: game_state::IsUnset, { /// Set the `syncStatus` field (required) pub fn sync_status( mut self, value: impl Into>, ) -> GameBuilder<'a, game_state::SetSyncStatus> { self._fields.4 = Option::Some(value.into()); GameBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S> GameBuilder<'a, S> where S: game_state::State, S::Won: game_state::IsUnset, { /// Set the `won` field (required) pub fn won( mut self, value: impl Into, ) -> GameBuilder<'a, game_state::SetWon> { self._fields.5 = Option::Some(value.into()); GameBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S> GameBuilder<'a, S> where S: game_state::State, S::Won: game_state::IsSet, S::Completed: game_state::IsSet, S::CurrentScore: game_state::IsSet, S::CreatedAt: game_state::IsSet, S::SeededRecording: game_state::IsSet, S::SyncStatus: game_state::IsSet, { /// Build the final struct pub fn build(self) -> Game<'a> { Game { completed: self._fields.0.unwrap(), created_at: self._fields.1.unwrap(), current_score: self._fields.2.unwrap(), seeded_recording: self._fields.3.unwrap(), sync_status: self._fields.4.unwrap(), won: self._fields.5.unwrap(), 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>, >, ) -> Game<'a> { Game { completed: self._fields.0.unwrap(), created_at: self._fields.1.unwrap(), current_score: self._fields.2.unwrap(), seeded_recording: self._fields.3.unwrap(), sync_status: self._fields.4.unwrap(), won: self._fields.5.unwrap(), extra_data: Some(extra_data), } } } fn lexicon_doc_blue_2048_game() -> 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("blue.2048.game"), defs: { let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("main"), LexUserType::Record(LexRecord { description: Some( CowStr::new_static( "A declaration of an instance of a at://2048 game", ), ), key: Some(CowStr::new_static("tid")), record: LexRecordRecord::Object(LexObject { required: Some( vec![ SmolStr::new_static("currentScore"), SmolStr::new_static("won"), SmolStr::new_static("completed"), SmolStr::new_static("seededRecording"), SmolStr::new_static("syncStatus"), SmolStr::new_static("createdAt") ], ), properties: { #[allow(unused_mut)] let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("completed"), LexObjectProperty::Boolean(LexBoolean { ..Default::default() }), ); map.insert( SmolStr::new_static("createdAt"), LexObjectProperty::String(LexString { format: Some(LexStringFormat::Datetime), ..Default::default() }), ); map.insert( SmolStr::new_static("currentScore"), LexObjectProperty::Integer(LexInteger { ..Default::default() }), ); map.insert( SmolStr::new_static("seededRecording"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static( "This is the recording of the game. Like chess notation, but for 2048", ), ), ..Default::default() }), ); map.insert( SmolStr::new_static("syncStatus"), LexObjectProperty::Ref(LexRef { r#ref: CowStr::new_static("blue.2048.defs#syncStatus"), ..Default::default() }), ); map.insert( SmolStr::new_static("won"), LexObjectProperty::Boolean(LexBoolean { ..Default::default() }), ); map }, ..Default::default() }), ..Default::default() }), ); map }, ..Default::default() } }