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
impl VersionedDirStorage
Sourcepub fn new(
paths: AppPaths,
category: impl Into<String>,
migrator: Migrator,
strategy: DirStorageStrategy,
) -> Result<Self, MigrationError>
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-Migratorinstance with registered migration paths.strategy- Storage strategy configuration (format, encoding, etc.).
§Errors
Returns MigrationError::Store if directory creation fails.
Sourcepub fn save<T>(
&self,
entity_name: impl Into<String>,
id: impl Into<String>,
entity: T,
) -> Result<(), MigrationError>where
T: Serialize,
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.
Sourcepub fn load<D>(
&self,
entity_name: impl Into<String>,
id: impl Into<String>,
) -> Result<D, MigrationError>where
D: DeserializeOwned,
pub fn load<D>(
&self,
entity_name: impl Into<String>,
id: impl Into<String>,
) -> Result<D, MigrationError>where
D: DeserializeOwned,
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.
Sourcepub fn list_ids(&self) -> Result<Vec<String>, MigrationError>
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.
Sourcepub fn load_all<D>(
&self,
entity_name: impl Into<String>,
) -> Result<Vec<(String, D)>, MigrationError>where
D: DeserializeOwned,
pub fn load_all<D>(
&self,
entity_name: impl Into<String>,
) -> Result<Vec<(String, D)>, MigrationError>where
D: DeserializeOwned,
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.