pub struct DirStorage { /* private fields */ }Expand description
Directory-based entity storage with ACID guarantees and automatic migrations.
Manages one file per entity. Raw IO (atomic rename, fsync, temp-file cleanup,
ID encoding/decoding, directory listing) is fully delegated to
local_store::DirStorage.
§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.
Implementations§
Source§impl DirStorage
impl DirStorage
Sourcepub fn new(
paths: AppPaths,
domain_name: &str,
migrator: Migrator,
strategy: DirStorageStrategy,
) -> Result<Self, MigrationError>
pub fn new( paths: AppPaths, domain_name: &str, migrator: Migrator, strategy: DirStorageStrategy, ) -> Result<Self, MigrationError>
Create a new DirStorage instance.
§Arguments
paths- Application paths manager.domain_name- Domain-specific subdirectory name (e.g.,"sessions").migrator- Migrator instance with registered migration paths.strategy- Storage strategy (format, encoding, atomic-write config).
§Behavior
Delegates directory creation to local_store::DirStorage::new. The base
path is resolved as data_dir/domain_name and created if absent.
§Errors
Returns MigrationError::Store wrapping a StoreError::IoError if
directory creation fails.
Sourcepub fn save<T>(
&self,
entity_name: &str,
id: &str,
entity: T,
) -> Result<(), MigrationError>where
T: Serialize,
pub fn save<T>(
&self,
entity_name: &str,
id: &str,
entity: T,
) -> Result<(), MigrationError>where
T: Serialize,
Save an entity to its file atomically.
§Arguments
entity_name- Entity name registered in the migrator.id- Unique identifier for this entity (used as the filename stem).entity- Value to persist; must implementserde::Serialize.
§Process
- Converts
entityto its latest versioned DTO viamigrator.save_domain_flat. - Serialises to the configured format (JSON or TOML).
- Delegates atomic write (tmp file + fsync + rename) to
inner.save_raw_string.
§Errors
Returns MigrationError if:
entity_nameis not registered in the migrator.idcontains invalid characters for the configured encoding.- Serialisation or format conversion fails.
- The underlying file write fails.
Sourcepub fn load<D>(&self, entity_name: &str, id: &str) -> Result<D, MigrationError>where
D: DeserializeOwned,
pub fn load<D>(&self, entity_name: &str, id: &str) -> Result<D, MigrationError>where
D: DeserializeOwned,
Load an entity from its file, applying schema migrations if needed.
§Arguments
entity_name- Entity name registered in the migrator.id- Unique identifier for the entity.
§Process
- Reads raw string content via
inner.load_raw_string. - Deserialises to
serde_json::Value(converting from TOML if needed). - Applies schema migration via
migrator.load_flat_from.
§Errors
Returns MigrationError if the file is missing, parsing fails, or
migration fails.
Sourcepub fn load_all<D>(
&self,
entity_name: &str,
) -> Result<Vec<(String, D)>, MigrationError>where
D: DeserializeOwned,
pub fn load_all<D>(
&self,
entity_name: &str,
) -> Result<Vec<(String, D)>, MigrationError>where
D: DeserializeOwned,
Auto Trait Implementations§
impl Freeze for DirStorage
impl !RefUnwindSafe for DirStorage
impl Send for DirStorage
impl Sync for DirStorage
impl Unpin for DirStorage
impl UnsafeUnpin for DirStorage
impl !UnwindSafe for DirStorage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more