Skip to main content

VersionedDirStorage

Struct VersionedDirStorage 

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

Version-aware directory-based entity storage.

Wraps local_store::DirStorage for raw IO and layers Migrator-based schema evolution on top.

§Responsibilities

  • Serialising/deserialising entities to/from the configured format.
  • Delegating all ACID / atomic-rename / lock operations to inner.
  • Applying migrator-based schema evolution on load.

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

Implementations§

Source§

impl VersionedDirStorage

Source

pub fn new( paths: AppPaths, category: impl Into<String>, migrator: Migrator, strategy: DirStorageStrategy, ) -> Result<Self, MigrationError>

Create a new VersionedDirStorage instance.

Resolves the base path as paths.data_dir()?.join(category), creates the directory when absent, and wraps the raw local_store::DirStorage.

§Arguments
  • paths - Application paths manager.
  • category - Domain-specific subdirectory name (e.g. "sessions").
  • migrator - Migrator instance with registered migration paths.
  • strategy - Storage strategy configuration (format, encoding, etc.).
§Errors

Returns MigrationError::Store if directory creation fails.

Source

pub fn save<T>( &self, entity_name: impl Into<String>, id: impl Into<String>, entity: T, ) -> Result<(), MigrationError>
where T: Serialize,

Save an entity to a file.

Converts the entity to its latest versioned DTO via Migrator::save_domain_flat, applies format serialisation, and writes atomically through local_store::DirStorage::save_raw_string.

§Errors

Returns MigrationError on serialisation failure, invalid ID characters, or IO errors.

Source

pub fn load<D>( &self, entity_name: impl Into<String>, id: impl Into<String>, ) -> Result<D, MigrationError>

Load an entity from a file.

Reads the raw string from local_store::DirStorage::load_raw_string, deserialises the content to a serde_json::Value, and migrates to the target domain type via Migrator::load_flat_from.

§Errors

Returns MigrationError if the file is not found, deserialisation fails, or migration fails.

Source

pub fn list_ids(&self) -> Result<Vec<String>, MigrationError>

List all entity IDs in the storage directory.

Delegates directly to local_store::DirStorage::list_ids.

§Errors

Returns MigrationError::Store on IO failure or MigrationError::FilenameEncoding when a stored filename cannot be decoded.

Source

pub fn load_all<D>( &self, entity_name: impl Into<String>, ) -> Result<Vec<(String, D)>, MigrationError>

Load all entities from the storage directory.

Calls list_ids and then load for each ID. If any load fails the entire operation fails.

§Errors

Returns the first MigrationError encountered during loading.

Source

pub fn exists(&self, id: impl Into<String>) -> Result<bool, MigrationError>

Check whether an entity file exists.

§Errors

Returns MigrationError::Store if ID encoding fails.

Source

pub fn delete(&self, id: impl Into<String>) -> Result<(), MigrationError>

Delete an entity file.

This operation is idempotent: deleting a non-existent file is not an error.

§Errors

Returns MigrationError::Store if file deletion fails.

Source

pub fn base_path(&self) -> &Path

Returns a reference to the base directory 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.