Skip to main content

StateStore

Trait StateStore 

Source
pub trait StateStore: Send + Sync {
    // Required methods
    fn store(&mut self, content: &str) -> StateRef;
    fn load(&self, state_ref: &StateRef) -> Option<String>;
    fn len(&self) -> usize;

    // Provided methods
    fn exists(&self, state_ref: &StateRef) -> bool { ... }
    fn is_empty(&self) -> bool { ... }
}
Expand description

Trait for content-addressed state storage.

Implementations must guarantee:

  1. store(content) returns the same StateRef for identical content
  2. load(ref) returns Some(content) if previously stored
  3. Content is immutable once stored

Required Methods§

Source

fn store(&mut self, content: &str) -> StateRef

Store content and return its reference.

If the content already exists, returns the existing reference without storing again (deduplication).

Source

fn load(&self, state_ref: &StateRef) -> Option<String>

Load content by reference.

Returns None if the reference is not found.

Source

fn len(&self) -> usize

Get the number of stored states.

Provided Methods§

Source

fn exists(&self, state_ref: &StateRef) -> bool

Check if a reference exists in the store.

Source

fn is_empty(&self) -> bool

Check if the store is empty.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§