pub struct FileStore { /* private fields */ }Expand description
Files live under root/owner/slot.fxsave. Root must be absolute.
Replacing an existing, structurally valid save retains its exact bytes in
slot.fxsave.bak. Malformed or oversized originals never replace that backup.
Loads still report the original file, including corruption; recovery is an
explicit operation using Self::recover. Temporary files left by a stopped
process are never loaded or promoted. Writers to the same slot should be
serialized when the ordering of backup generations matters.
Implementations§
Source§impl FileStore
impl FileStore
pub fn new(root: PathBuf) -> Result<FileStore, StorageError>
pub fn platform() -> Result<FileStore, StorageError>
pub fn root(&self) -> &Path
Sourcepub fn recover<T>(&self, owner: &str, slot: &str) -> Result<bool, StorageError>where
T: SaveData,
pub fn recover<T>(&self, owner: &str, slot: &str) -> Result<bool, StorageError>where
T: SaveData,
Restore the previous save only after validating it as T.
Returns false when no backup exists. Invalid, incompatible, oversized or
unreadable backups return an error without changing the current file. A
successful recovery copies the backup atomically, preserving its original
generation and the backup itself. Reopen any cached Slot afterwards.
This also allows an explicit rollback of a healthy current save.
DurabilityUncertain means the replacement completed but synchronizing
its directory failed. Other errors leave the destination uncommitted.
use ferravex_render::storage::{FileStore, RecordBook, Slot, StorageError};
let files = FileStore::platform()?;
if files.recover::<RecordBook>("my-game", "records")? {
let restored = Slot::with_backend(
"my-game", "records", RecordBook::default(), files,
)?;
assert!(restored.generation() > 0);
}