pub struct Game { /* private fields */ }Expand description
Represents a game with a host, optional guest (i.e. no one has joined and game is deemed to be in the lobby), name, and current state.
Implementations§
Source§impl Game
impl Game
Sourcepub fn new(
id: GameId,
host: UserId,
guest: Option<UserId>,
name: &str,
state: Phase,
) -> Self
pub fn new( id: GameId, host: UserId, guest: Option<UserId>, name: &str, state: Phase, ) -> Self
Creates a new Game with the specified ID, host, optional guest, name, and state.
Sourcepub fn validate_user(&self, user_id: UserId) -> Option<Player>
pub fn validate_user(&self, user_id: UserId) -> Option<Player>
Returns the player corresponding to the given user ID, if they are part of this game.
Trait Implementations§
Source§impl Aggregate for Game
impl Aggregate for Game
Source§const TYPE: &'static str = "Game"
const TYPE: &'static str = "Game"
The aggregate type is used as the unique identifier for this aggregate and its events.
This is used for persisting the events and snapshots to a database.
Source§type Command = GameCommand
type Command = GameCommand
Specifies the inbound command used to make changes in the state of the Aggregate.
Source§type Event = GameEvent
type Event = GameEvent
Specifies the published events representing some change in state of the Aggregate.
Source§type Error = DomainError
type Error = DomainError
The error returned when a command fails due to business logic.
This is used to provide feedback to the user as to the nature of why the command was refused.
Source§type Services = GameServices
type Services = GameServices
The external services required for the logic within the Aggregate
Source§async fn handle(
&mut self,
command: Self::Command,
_services: &Self::Services,
sink: &EventSink<Self>,
) -> Result<(), Self::Error>
async fn handle( &mut self, command: Self::Command, _services: &Self::Services, sink: &EventSink<Self>, ) -> Result<(), Self::Error>
This method consumes and processes commands.
The result should be either a vector of events if the command is successful,
or an error if the command is rejected. Read more
Source§impl<'de> Deserialize<'de> for Game
impl<'de> Deserialize<'de> for Game
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Game
impl StructuralPartialEq for Game
Auto Trait Implementations§
impl Freeze for Game
impl RefUnwindSafe for Game
impl Send for Game
impl Sync for Game
impl Unpin for Game
impl UnwindSafe for Game
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more