Skip to main content

VersionedFileStorage

Struct VersionedFileStorage 

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

Version-aware file storage that wraps local_store::FileStorage.

§Responsibilities

This struct handles only:

  • Constructing a ConfigMigrator from the file content on init.
  • Format dispatch (TOML ↔ JSON serialisation) on save.
  • Delegating all ACID / atomic-rename / lock operations to inner.

Raw IO (atomic_rename, get_temp_path, cleanup_temp_files) lives exclusively inside local_store::FileStorage.

Implementations§

Source§

impl VersionedFileStorage

Source

pub fn new( path: PathBuf, migrator: Migrator, strategy: FileStorageStrategy, ) -> Result<Self, MigrationError>

Create a new VersionedFileStorage instance and load data from the file.

Reads the file (if present), applies TOML→JSON conversion when needed, constructs a ConfigMigrator from the resulting JSON string, and—when LoadBehavior::SaveIfMissing is configured—writes the initial content to disk.

§Arguments
  • path - Path to the storage file.
  • migrator - Migrator instance with registered migration paths.
  • strategy - Storage strategy (format, load behaviour, atomic-write config).
§Errors

Returns MigrationError::Store on IO failure or MigrationError::TomlParseError / MigrationError::SerializationError on format conversion failure. Returns MigrationError::Store(IoError) when LoadBehavior::ErrorIfMissing is set and the file is absent.

Source

pub fn save(&self) -> Result<(), MigrationError>

Save the current in-memory state to the file atomically.

Serialises the ConfigMigrator value to the configured format (TOML or JSON) and delegates the atomic write (tmp file + fsync + rename) to local_store::FileStorage::write_string.

§Errors

Returns MigrationError::Store on IO failure or MigrationError::TomlSerializeError / MigrationError::SerializationError on serialisation failure.

Source

pub fn config(&self) -> &ConfigMigrator

Get an immutable reference to the ConfigMigrator.

Source

pub fn config_mut(&mut self) -> &mut ConfigMigrator

Get a mutable reference to the ConfigMigrator.

Source

pub fn query<T>(&self, key: &str) -> Result<Vec<T>, MigrationError>
where T: Queryable + for<'de> Deserialize<'de>,

Query entities from the in-memory configuration.

Delegates to ConfigMigrator::query.

§Errors

Returns MigrationError if the key is not found or deserialisation fails.

Source

pub fn update<T>( &mut self, key: &str, value: Vec<T>, ) -> Result<(), MigrationError>
where T: Queryable + Serialize,

Update entities in memory without saving to disk.

Delegates to ConfigMigrator::update.

§Errors

Returns MigrationError if serialisation or internal update fails.

Source

pub fn update_and_save<T>( &mut self, key: &str, value: Vec<T>, ) -> Result<(), MigrationError>
where T: Queryable + Serialize,

Update entities in memory and immediately save to disk atomically.

Combines update and save in a single operation.

§Errors

Returns MigrationError on update or IO failure.

Source

pub fn path(&self) -> &Path

Returns a reference to the storage file path.

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.