Skip to main content

DirStorage

Struct DirStorage 

Source
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: fsync is called before the rename.
  • Idempotent delete: calling delete on a missing ID returns Ok(()).

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

Source

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 resolve data_dir.
  • category - Sub-directory name appended to data_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.

Source

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::FilenameEncoding if id cannot be encoded with the configured strategy.
  • StoreError::IoError if the file cannot be written.
Source

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

Read the raw string content for an entity.

§Arguments
  • id - Unique identifier for the entity.
§Returns

The UTF-8 string content stored for id.

§Errors
  • StoreError::FilenameEncoding if id cannot be encoded.
  • StoreError::IoError { operation: Read, … } if the file is missing or cannot be read.
Source

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::FilenameEncoding if a filename cannot be decoded.
Source

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

Check whether an entity file exists.

§Arguments
  • id - Entity identifier.
§Returns

true if the encoded file exists and is a regular file; false otherwise.

§Errors

StoreError::FilenameEncoding if id cannot be encoded.

Source

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::FilenameEncoding if id cannot be encoded.
  • StoreError::IoError { operation: Delete, … } if the file exists but cannot be removed.
Source

pub fn base_path(&self) -> &Path

Returns a reference to the resolved base directory path.

§Returns

The absolute Path at which entity files are stored.

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.