pub struct Db { /* private fields */ }Expand description
Database for persisting game and players state.
Implementations§
Source§impl Db
impl Db
Sourcepub fn open_in_memory() -> Result<Self>
pub fn open_in_memory() -> Result<Self>
Open an in memory database.
Sourcepub async fn join_server(
&self,
player_id: PeerId,
nickname: &str,
join_chips: Chips,
) -> Result<Player>
pub async fn join_server( &self, player_id: PeerId, nickname: &str, join_chips: Chips, ) -> Result<Player>
A player join the server.
If the player doesn’t exist it creates one with the given chips, for now if the player exists but has fewer chips than join chips the chips are updated so that the player has enough chips to join.
Sourcepub async fn pay_from_player(
&self,
player_id: PeerId,
amount: Chips,
) -> Result<bool>
pub async fn pay_from_player( &self, player_id: PeerId, amount: Chips, ) -> Result<bool>
Pay an amount of chips from a player.
Returns Ok(false) if the player doesn’t have enough chips or an error if the player cannot be found.
Sourcepub async fn pay_to_player(
&self,
player_id: PeerId,
amount: Chips,
) -> Result<()>
pub async fn pay_to_player( &self, player_id: PeerId, amount: Chips, ) -> Result<()>
Pay an amount of chips to a player.
Returns an error if the player has not been found.
Sourcepub async fn get_player(&self, player_id: PeerId) -> Result<Player>
pub async fn get_player(&self, player_id: PeerId) -> Result<Player>
Returns the player with the given id.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Db
impl !RefUnwindSafe for Db
impl Send for Db
impl Sync for Db
impl Unpin for Db
impl UnsafeUnpin for Db
impl !UnwindSafe for Db
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