Skip to main content

LocalSession

Struct LocalSession 

Source
pub struct LocalSession<G: Game> { /* private fields */ }
Expand description

An in-memory game: owns a Game and its state, and applies requests to them directly. No file, socket, or other I/O, and no serialization: the typed Request/Response pass straight through.

This is the authority. A crate::FileSession is a thin wrapper that loads one of these, submits a single request, and saves it back; a long-lived server would hold one across many requests.

A committed chance node (PlayerId::CHANCE active) is resolved automatically from chance, so submit only ever returns control at a player decision or a terminal state, never stuck on a deck deal a client cannot make. chance is seeded from the match seed but offset, so it does not share a stream with the game’s own in-state generator.

Implementations§

Source§

impl<G: Game> LocalSession<G>

Source

pub fn new(game: G, state: G::State, seed: u64) -> Self

Starts a session over game at state, at version 0, with the chance sampler seeded from seed. Any chance node the opening position starts on (e.g. an initial deal) is resolved immediately.

Source

pub const fn resume( game: G, state: G::State, version: u64, chance: Prng, ) -> Self

Resumes a session at a previously saved state, version, and chance sampler, e.g. from a crate::FileSession save file. Does not re-resolve chance: a saved position is always left at a player decision or terminal, never mid-chance.

Source

pub const fn game(&self) -> &G

Returns the rules governing this session.

Source

pub const fn state(&self) -> &G::State

Returns the current authoritative state, e.g. to persist or inspect it.

Source

pub const fn version(&self) -> u64

Returns the current version: the number of actions (player and chance) applied so far.

Source

pub fn into_parts(self) -> (G, G::State, u64, Prng)

Consumes the session, returning its parts for persistence.

Trait Implementations§

Source§

impl<G: Game> Session<G> for LocalSession<G>

Source§

fn submit( &mut self, player: PlayerId, request: Request<G::Action>, ) -> Response<G::View>

Applies request on behalf of player and returns the response.

Auto Trait Implementations§

§

impl<G> Freeze for LocalSession<G>
where G: Freeze, <G as Game>::State: Freeze,

§

impl<G> RefUnwindSafe for LocalSession<G>

§

impl<G> Send for LocalSession<G>
where G: Send, <G as Game>::State: Send,

§

impl<G> Sync for LocalSession<G>
where G: Sync, <G as Game>::State: Sync,

§

impl<G> Unpin for LocalSession<G>
where G: Unpin, <G as Game>::State: Unpin,

§

impl<G> UnsafeUnpin for LocalSession<G>
where G: UnsafeUnpin, <G as Game>::State: UnsafeUnpin,

§

impl<G> UnwindSafe for LocalSession<G>
where G: UnwindSafe, <G as Game>::State: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.