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
impl FileSession
Sourcepub fn create<G>(
game: G,
path: Option<PathBuf>,
state: G::State,
seed: u64,
) -> Result<PathBuf, Error>
pub fn create<G>( game: G, path: Option<PathBuf>, state: G::State, seed: u64, ) -> Result<PathBuf, Error>
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.
Sourcepub fn handle<G>(
path: &Path,
player: PlayerId,
request: Request<G::Action>,
) -> Result<Response<G::View>, Error>
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.