Struct FileStore

Source
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

Source

pub fn new(root: PathBuf) -> Result<FileStore, StorageError>

Source

pub fn platform() -> Result<FileStore, StorageError>

Source

pub fn root(&self) -> &Path

Source

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);
}

Trait Implementations§

Source§

impl Backend for FileStore

Source§

fn load( &self, owner: &str, slot: &str, limit: usize, ) -> Result<Option<Vec<u8>>, StorageError>

Source§

fn store( &self, owner: &str, slot: &str, bytes: &[u8], ) -> Result<(), StorageError>

DurabilityUncertain means complete data replaced the destination, but the parent-directory durability check failed. Other errors do not confirm commit.
Source§

fn is_transient(&self) -> bool

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.