Skip to main content

Store

Trait Store 

Source
pub trait Store: Send + Sync {
    type Error: Error + Send + Sync + 'static;

Show 13 methods // Required methods fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error>; fn put(&self, key: &[u8], value: &[u8]) -> Result<(), Self::Error>; fn delete(&self, key: &[u8]) -> Result<(), Self::Error>; fn batch(&self, ops: &[BatchOp<'_>]) -> Result<(), Self::Error>; // Provided methods fn batch_get( &self, keys: &[&[u8]], ) -> Result<HashMap<Vec<u8>, Vec<u8>>, Self::Error> { ... } fn batch_get_ordered( &self, keys: &[&[u8]], ) -> Result<Vec<Option<Vec<u8>>>, Self::Error> { ... } fn batch_get_ordered_unique( &self, keys: &[&[u8]], ) -> Result<Vec<Option<Vec<u8>>>, Self::Error> { ... } fn prefers_batch_reads(&self) -> bool { ... } fn batch_put(&self, entries: &[(&[u8], &[u8])]) -> Result<(), Self::Error> { ... } fn supports_hints(&self) -> bool { ... } fn get_hint( &self, namespace: &[u8], key: &[u8], ) -> Result<Option<Vec<u8>>, Self::Error> { ... } fn put_hint( &self, namespace: &[u8], key: &[u8], value: &[u8], ) -> Result<(), Self::Error> { ... } fn batch_put_with_hint( &self, entries: &[(&[u8], &[u8])], namespace: &[u8], key: &[u8], value: &[u8], ) -> Result<(), Self::Error> { ... }
}
Expand description

Storage backend trait for Prolly Trees

Keys are CID bytes, values are serialized nodes. Implementations must be thread-safe (Send + Sync).

Required Associated Types§

Source

type Error: Error + Send + Sync + 'static

Error type for storage operations

Required Methods§

Source

fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error>

Get value by key

Returns Ok(Some(value)) if key exists, Ok(None) if not found, or Err on storage failure.

Source

fn put(&self, key: &[u8], value: &[u8]) -> Result<(), Self::Error>

Store key-value pair

Inserts or updates the value for the given key.

Source

fn delete(&self, key: &[u8]) -> Result<(), Self::Error>

Delete key

Removes the key if it exists. No error if key doesn’t exist.

Source

fn batch(&self, ops: &[BatchOp<'_>]) -> Result<(), Self::Error>

Batch write operations (atomic if supported by backend)

Applies all operations in the batch. Implementations should attempt to make this atomic when possible.

Provided Methods§

Source

fn batch_get( &self, keys: &[&[u8]], ) -> Result<HashMap<Vec<u8>, Vec<u8>>, Self::Error>

Retrieve multiple keys in a single operation

Returns a HashMap mapping each requested key to its value (if found). Keys that don’t exist are simply not included in the result.

The default implementation uses sequential gets, but implementations can override this for better performance.

Source

fn batch_get_ordered( &self, keys: &[&[u8]], ) -> Result<Vec<Option<Vec<u8>>>, Self::Error>

Retrieve multiple keys in a single operation with order preservation

Returns a Vec of Option<Vec<u8>> in the same order as the input keys. Each element is Some(value) if the key exists, or None if not found.

This method is useful when the order of results must match the order of input keys, such as when prefetching nodes for batch operations.

The default implementation uses sequential gets, but implementations with parallel I/O capabilities (e.g., network stores) can override this for better performance.

§Arguments
  • keys - Slice of keys to retrieve
§Returns

Vector of Option<Vec<u8>> in the same order as input keys. None indicates the key was not found.

Source

fn batch_get_ordered_unique( &self, keys: &[&[u8]], ) -> Result<Vec<Option<Vec<u8>>>, Self::Error>

Retrieve unique keys in input order.

This is a fast path for callers that have already deduplicated keys and still need order preservation. The default keeps efficient custom batch_get_ordered implementations for stores that prefer batched reads, while avoiding duplicate-planning overhead for point-read stores.

Source

fn prefers_batch_reads(&self) -> bool

Whether this store has an efficient batched-read implementation.

The prolly engine uses this to decide whether to prefetch many tree paths through batch_get_ordered. Stores that implement true multi-get, request coalescing, or parallel remote reads should return true.

Source

fn batch_put(&self, entries: &[(&[u8], &[u8])]) -> Result<(), Self::Error>

Store multiple key-value pairs in a single operation

Writes all entries atomically when possible. The default implementation uses the existing batch method with Upsert operations.

Implementations can override this for better performance.

Source

fn supports_hints(&self) -> bool

Whether this store persists performance hints.

Source

fn get_hint( &self, namespace: &[u8], key: &[u8], ) -> Result<Option<Vec<u8>>, Self::Error>

Retrieve an optional performance hint for a logical namespace and key.

Hints are not part of the content-addressed tree semantics. Store implementations may ignore them and return None; callers must always have a correct fallback path.

Source

fn put_hint( &self, namespace: &[u8], key: &[u8], value: &[u8], ) -> Result<(), Self::Error>

Persist an optional performance hint for a logical namespace and key.

The default implementation is a no-op so custom stores remain compatible.

Source

fn batch_put_with_hint( &self, entries: &[(&[u8], &[u8])], namespace: &[u8], key: &[u8], value: &[u8], ) -> Result<(), Self::Error>

Store content-addressed nodes and one hint atomically when supported.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<T: Store> Store for Arc<T>

Implement Store for Arc<T> where T: Store This allows sharing a store between multiple Prolly instances

Source§

type Error = <T as Store>::Error

Source§

fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error>

Source§

fn put(&self, key: &[u8], value: &[u8]) -> Result<(), Self::Error>

Source§

fn delete(&self, key: &[u8]) -> Result<(), Self::Error>

Source§

fn batch(&self, ops: &[BatchOp<'_>]) -> Result<(), Self::Error>

Source§

fn batch_get( &self, keys: &[&[u8]], ) -> Result<HashMap<Vec<u8>, Vec<u8>>, Self::Error>

Source§

fn batch_get_ordered( &self, keys: &[&[u8]], ) -> Result<Vec<Option<Vec<u8>>>, Self::Error>

Source§

fn batch_get_ordered_unique( &self, keys: &[&[u8]], ) -> Result<Vec<Option<Vec<u8>>>, Self::Error>

Source§

fn prefers_batch_reads(&self) -> bool

Source§

fn batch_put(&self, entries: &[(&[u8], &[u8])]) -> Result<(), Self::Error>

Source§

fn supports_hints(&self) -> bool

Source§

fn get_hint( &self, namespace: &[u8], key: &[u8], ) -> Result<Option<Vec<u8>>, Self::Error>

Source§

fn put_hint( &self, namespace: &[u8], key: &[u8], value: &[u8], ) -> Result<(), Self::Error>

Source§

fn batch_put_with_hint( &self, entries: &[(&[u8], &[u8])], namespace: &[u8], key: &[u8], value: &[u8], ) -> Result<(), Self::Error>

Implementors§