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§
Required Methods§
Sourcefn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error>
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.
Sourcefn put(&self, key: &[u8], value: &[u8]) -> Result<(), Self::Error>
fn put(&self, key: &[u8], value: &[u8]) -> Result<(), Self::Error>
Store key-value pair
Inserts or updates the value for the given key.
Provided Methods§
Sourcefn batch_get(
&self,
keys: &[&[u8]],
) -> Result<HashMap<Vec<u8>, Vec<u8>>, Self::Error>
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.
Sourcefn batch_get_ordered(
&self,
keys: &[&[u8]],
) -> Result<Vec<Option<Vec<u8>>>, Self::Error>
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.
Sourcefn batch_get_ordered_unique(
&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>
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.
Sourcefn prefers_batch_reads(&self) -> bool
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.
Sourcefn batch_put(&self, entries: &[(&[u8], &[u8])]) -> Result<(), Self::Error>
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.
Sourcefn supports_hints(&self) -> bool
fn supports_hints(&self) -> bool
Whether this store persists performance hints.
Sourcefn get_hint(
&self,
namespace: &[u8],
key: &[u8],
) -> Result<Option<Vec<u8>>, Self::Error>
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.
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
impl<T: Store> Store for Arc<T>
Implement Store for Arc<T> where T: Store
This allows sharing a store between multiple Prolly instances