StateStore

Trait StateStore 

Source
pub trait StateStore: Send + Sync {
    // Required methods
    fn load(&self) -> LoadResult;
    fn save(
        &self,
        snapshots: &[AdapterSnapshot],
    ) -> impl Future<Output = Result<(), StateError>> + Send;
}
Expand description

Abstraction for persisting adapter state between program runs.

Implementations should:

  • Use atomic writes to prevent corruption from crashes
  • Handle missing files gracefully (return LoadResult::NotFound)
  • Degrade gracefully on read errors (return LoadResult::Corrupted)

§Testing

Use [MockStateStore] in tests to avoid filesystem dependencies.

Required Methods§

Source

fn load(&self) -> LoadResult

Loads previously saved state.

Returns one of:

  • LoadResult::Loaded - State was successfully loaded
  • LoadResult::NotFound - No state file exists
  • LoadResult::Corrupted - State file exists but is invalid
Source

fn save( &self, snapshots: &[AdapterSnapshot], ) -> impl Future<Output = Result<(), StateError>> + Send

Saves current adapter state for future reference.

Implementations should use atomic write semantics (write to temp file, then rename) to prevent corruption if the program crashes mid-write.

§Errors

Returns an error if the state cannot be written.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§