Skip to main content

FileSession

Struct FileSession 

Source
pub struct FileSession;
Expand description

A stateless, file-backed adapter over LocalSession: create a save, then query or drive it across separate process invocations.

Implementations§

Source§

impl FileSession

Source

pub fn create<G>( game: G, path: Option<PathBuf>, state: G::State, seed: u64, ) -> Result<PathBuf, Error>
where G: Game + Serialize, G::State: Serialize,

Creates a new save file holding game at state, its chance sampler seeded from seed, and returns its resolved path. Any chance node the opening position starts on is resolved before the save is written. Never overwrites an existing file.

path’s None case generates one under the system temp directory, so a caller need not name a file up front.

§Errors

Returns Error::AlreadyExists if path is Some and a file is already there, or Error::Io/Error::Serde if writing fails.

Source

pub fn handle<G>( path: &Path, player: PlayerId, request: Request<G::Action>, ) -> Result<Response<G::View>, Error>

Loads the save at path, applies request for player, saves back if an action was applied, and returns the response.

A Request::Query and a rejected action leave the file untouched; only a successful apply (Response::Ack) is persisted.

§Errors

Returns Error::NotFound if path does not exist, Error::ProtocolMismatch if the save was written by an incompatible protocol version, Error::Serde if it does not parse, or Error::Io if reading or writing fails.

Auto Trait Implementations§

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.