pub struct DirStorage { /* private fields */ }Expand description
Raw directory-based entity storage with ACID guarantees.
Manages one file per entity and provides:
- Atomicity: writes use a temporary file followed by an atomic rename.
- Durability:
fsyncis called before the rename. - Idempotent delete: calling
deleteon a missing ID returnsOk(()).
This type holds no Migrator and performs no schema migration.
Content is stored and retrieved as opaque UTF-8 strings; callers are
responsible for any serialisation/deserialisation.
Implementations§
Source§impl DirStorage
impl DirStorage
Sourcepub fn new(
paths: AppPaths,
category: impl Into<String>,
strategy: DirStorageStrategy,
) -> Result<Self, StoreError>
pub fn new( paths: AppPaths, category: impl Into<String>, strategy: DirStorageStrategy, ) -> Result<Self, StoreError>
Create a new DirStorage instance.
§Arguments
paths- Application path manager used to resolvedata_dir.category- Sub-directory name appended todata_dir(e.g."sessions").strategy- Storage strategy configuration.
§Returns
Ok(DirStorage) with base_path = data_dir/category.
§Errors
Returns StoreError::HomeDirNotFound if data_dir cannot be resolved,
or StoreError::IoError { operation: CreateDir, … } if the base
directory cannot be created.
Sourcepub fn save_raw_string(
&self,
_entity_name: impl Into<String>,
id: impl Into<String>,
content: &str,
) -> Result<(), StoreError>
pub fn save_raw_string( &self, _entity_name: impl Into<String>, id: impl Into<String>, content: &str, ) -> Result<(), StoreError>
Write raw string content for an entity, atomically.
§Arguments
entity_name- Logical entity type name (informational; not used in the file path).id- Unique identifier for this entity (encoded into the filename).content- UTF-8 string to persist verbatim.
§Returns
Ok(()) on success.
§Errors
StoreError::FilenameEncodingifidcannot be encoded with the configured strategy.StoreError::IoErrorif the file cannot be written.
Sourcepub fn load_raw_string(
&self,
id: impl Into<String>,
) -> Result<String, StoreError>
pub fn load_raw_string( &self, id: impl Into<String>, ) -> Result<String, StoreError>
Sourcepub fn list_ids(&self) -> Result<Vec<String>, StoreError>
pub fn list_ids(&self) -> Result<Vec<String>, StoreError>
List all entity IDs stored in the base directory.
Only files whose extension matches strategy.get_extension() are
included. Temporary files (.tmp.*) are excluded because their
extension is tmp, not the configured extension.
§Returns
A sorted Vec<String> of decoded entity IDs.
§Errors
StoreError::IoError { operation: ReadDir, … }if the directory cannot be read.StoreError::FilenameEncodingif a filename cannot be decoded.
Sourcepub fn delete(&self, id: impl Into<String>) -> Result<(), StoreError>
pub fn delete(&self, id: impl Into<String>) -> Result<(), StoreError>
Delete the file associated with an entity ID.
This operation is idempotent: if the file does not exist, Ok(())
is returned without error (matches original behaviour at
dir_storage.rs:760-775).
§Arguments
id- Entity identifier.
§Returns
Ok(()) whether or not the file existed.
§Errors
StoreError::FilenameEncodingifidcannot be encoded.StoreError::IoError { operation: Delete, … }if the file exists but cannot be removed.