Skip to main content

Store

Trait Store 

Source
pub trait Store<T>: Send + Sync
where T: Send + Sync + 'static + Clone + Serialize,
{ type Error; type Key;
Show 13 methods // Required methods fn open(&self) -> Result<(), Self::Error>; fn put(&self, item: Arc<T>) -> Result<Self::Key, Self::Error>; fn put_multiple(&self, items: Vec<T>) -> Result<Self::Key, Self::Error>; fn put_raw(&self, data: &[u8]) -> Result<Self::Key, Self::Error>; fn get(&self, key: &Self::Key) -> Result<T, Self::Error>; fn get_multiple(&self, key: &Self::Key) -> Result<Vec<T>, Self::Error>; fn get_raw(&self, key: &Self::Key) -> Result<Vec<u8>, Self::Error>; fn del(&self, key: &Self::Key) -> Result<(), Self::Error>; fn delete(&self) -> Result<(), Self::Error>; fn list(&self) -> Vec<Self::Key>; fn len(&self) -> usize; fn is_empty(&self) -> bool; fn boxed_clone( &self, ) -> Box<dyn Store<T, Error = Self::Error, Key = Self::Key> + Send + Sync>;
}
Expand description

Trait for a store that can store and retrieve items of type T

Required Associated Types§

Source

type Error

The error type for the store

Source

type Key

The key type for the store

Required Methods§

Source

fn open(&self) -> Result<(), Self::Error>

Opens the store

Source

fn put(&self, item: Arc<T>) -> Result<Self::Key, Self::Error>

Stores a single item

Source

fn put_multiple(&self, items: Vec<T>) -> Result<Self::Key, Self::Error>

Stores multiple items in a single batch

Source

fn put_raw(&self, data: &[u8]) -> Result<Self::Key, Self::Error>

Stores raw bytes in a single entry.

Source

fn get(&self, key: &Self::Key) -> Result<T, Self::Error>

Retrieves a single item by key

Source

fn get_multiple(&self, key: &Self::Key) -> Result<Vec<T>, Self::Error>

Retrieves multiple items by key

Source

fn get_raw(&self, key: &Self::Key) -> Result<Vec<u8>, Self::Error>

Retrieves the raw bytes stored for a key.

Source

fn del(&self, key: &Self::Key) -> Result<(), Self::Error>

Deletes an item by key

Source

fn delete(&self) -> Result<(), Self::Error>

Deletes the underlying store directory and clears all in-memory state.

Source

fn list(&self) -> Vec<Self::Key>

Lists all keys in the store

Source

fn len(&self) -> usize

Returns the number of items in the store

Source

fn is_empty(&self) -> bool

Returns true if the store is empty

Source

fn boxed_clone( &self, ) -> Box<dyn Store<T, Error = Self::Error, Key = Self::Key> + Send + Sync>

Clones the store into a boxed trait object

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<T> Store<T> for QueueStore<T>
where T: Serialize + DeserializeOwned + Clone + Send + Sync + 'static,