pub struct VersionedFileStorage { /* private fields */ }Expand description
Version-aware file storage that wraps local_store::FileStorage.
§Responsibilities
This struct handles only:
- Constructing a
ConfigMigratorfrom 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
impl VersionedFileStorage
Sourcepub fn new(
path: PathBuf,
migrator: Migrator,
strategy: FileStorageStrategy,
) -> Result<Self, MigrationError>
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-Migratorinstance 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.
Sourcepub fn save(&self) -> Result<(), MigrationError>
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.
Sourcepub fn config(&self) -> &ConfigMigrator
pub fn config(&self) -> &ConfigMigrator
Get an immutable reference to the ConfigMigrator.
Sourcepub fn config_mut(&mut self) -> &mut ConfigMigrator
pub fn config_mut(&mut self) -> &mut ConfigMigrator
Get a mutable reference to the ConfigMigrator.
Sourcepub fn query<T>(&self, key: &str) -> Result<Vec<T>, MigrationError>where
T: Queryable + for<'de> Deserialize<'de>,
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.
Sourcepub fn update<T>(
&mut self,
key: &str,
value: Vec<T>,
) -> Result<(), MigrationError>
pub fn update<T>( &mut self, key: &str, value: Vec<T>, ) -> Result<(), MigrationError>
Update entities in memory without saving to disk.
Delegates to ConfigMigrator::update.
§Errors
Returns MigrationError if serialisation or internal update fails.
Sourcepub fn update_and_save<T>(
&mut self,
key: &str,
value: Vec<T>,
) -> Result<(), MigrationError>
pub fn update_and_save<T>( &mut self, key: &str, value: Vec<T>, ) -> Result<(), MigrationError>
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.