Skip to main content

StateFile

Struct StateFile 

Source
pub struct StateFile { /* private fields */ }
Expand description

Plain atomic-rename state file: 24-byte header [magic:8, schema:u32, len:u32, xxh64:u64] + payload, where xxh64 covers both the 16-byte header prefix and the payload bytes.

Implementations§

Source§

impl StateFile

Source

pub fn open( path: impl AsRef<Path>, schema_version: u32, ) -> Result<Self, PersistenceError>

Source

pub fn open_with_sync( path: impl AsRef<Path>, schema_version: u32, sync_on_save: bool, ) -> Result<Self, PersistenceError>

Source

pub fn new_in_memory(schema_version: u32) -> Self

Source

pub fn path(&self) -> Option<&Path>

Source

pub fn schema_version(&self) -> u32

Source

pub fn generation(&self) -> u64

Source

pub fn recovery_stats(&self) -> StateRecoveryStats

Source

pub fn encode_envelope( schema_version: u32, payload: &[u8], ) -> Result<Vec<u8>, PersistenceError>

Source

pub fn decode_envelope( bytes: &[u8], expected_schema: u32, ) -> Result<&[u8], PersistenceError>

Source

pub fn load(&self) -> Result<Option<Vec<u8>>, PersistenceError>

Returns the validated payload read on open or written by the last Self::save without re-reading or re-hashing the file from disk.

Source

pub fn save( &mut self, payload: &[u8], ) -> Result<StateSaveOutcome, PersistenceError>

Source

pub fn quarantine_corrupt(&mut self) -> Result<(), PersistenceError>

Moves a payload-corrupt state file aside to <file>.corrupt and clears cached state.

Source

pub fn reset(&mut self) -> Result<(), PersistenceError>

Source

pub fn remove(path: &Path) -> Result<(), PersistenceError>

Deletes the state file at path (a cold start); succeeds when it is already absent.

Auto Trait Implementations§

§

impl Forget for StateFile

§

impl Freeze for StateFile
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for StateFile

§

impl RefUnwindSafe for StateFile

§

impl Send for StateFile
where RawVecInner: Send,

§

impl Sync for StateFile
where RawVecInner: Sync,

§

impl Unpin for StateFile
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for StateFile

§

impl UnwindSafe for StateFile
where RawVecInner: 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.