pub trait Datastore: Send + Sync {
// Required methods
fn protocol(&self) -> Protocol;
fn dispatch(&self, req: Msg) -> BoxFuture<'_, Result<Msg, DatastoreError>>;
// Provided methods
fn supports(&self, _cmd: MsgType) -> bool { ... }
fn list_buckets_stream(&self) -> DatastoreByteStream { ... }
fn list_keys_stream(&self, _bucket: &[u8]) -> DatastoreByteStream { ... }
fn riak_get<'a>(
&'a self,
_bucket: &'a [u8],
_key: &'a [u8],
) -> BoxFuture<'a, Result<Option<Vec<u8>>, DatastoreError>> { ... }
fn riak_put<'a>(
&'a self,
_bucket: &'a [u8],
_key: &'a [u8],
_value: &'a [u8],
_indexes: &'a [(Vec<u8>, Vec<u8>)],
) -> BoxFuture<'a, Result<(), DatastoreError>> { ... }
fn riak_delete<'a>(
&'a self,
_bucket: &'a [u8],
_key: &'a [u8],
) -> BoxFuture<'a, Result<bool, DatastoreError>> { ... }
fn riak_index_eq<'a>(
&'a self,
_bucket: &'a [u8],
_index_name: &'a [u8],
_value: &'a [u8],
) -> BoxFuture<'a, Result<Vec<Vec<u8>>, DatastoreError>> { ... }
fn riak_index_range<'a>(
&'a self,
_bucket: &'a [u8],
_index_name: &'a [u8],
_min: &'a [u8],
_max: &'a [u8],
) -> BoxFuture<'a, Result<Vec<Vec<u8>>, DatastoreError>> { ... }
}Expand description
Backing datastore the engine forwards routed requests to.
Implementations are kept stateless on the trait surface; live
connection state lives behind Datastore::dispatch in the
implementor’s chosen pool.
§Examples
use dynomite::embed::hooks::{Datastore, MemoryDatastore, Protocol};
use dynomite::msg::{Msg, MsgType};
let ds = MemoryDatastore::new();
assert_eq!(ds.protocol(), Protocol::Custom);
let req = Msg::new(1, MsgType::ReqRedisGet, true);
let _rsp = ds.dispatch(req).await.unwrap();
assert_eq!(ds.dispatch_count(), 1);Required Methods§
Provided Methods§
Sourcefn supports(&self, _cmd: MsgType) -> bool
fn supports(&self, _cmd: MsgType) -> bool
Predicate used by the dispatcher to short-circuit commands the backend cannot serve.
Sourcefn list_buckets_stream(&self) -> DatastoreByteStream
fn list_buckets_stream(&self) -> DatastoreByteStream
Stream the names of every bucket the datastore is aware of,
one bytes::Bytes per bucket.
The default implementation returns a one-shot stream that
yields a single DatastoreError::Unsupported item, so an
existing impl that does not enumerate buckets does not have
to be modified to compile against the new trait surface.
Implementations that can enumerate override this method.
The returned stream is 'static and Send; transports that
stream chunks of bucket names to clients (PBC frames, HTTP
chunked bodies, …) consume it from a tokio task.
Sourcefn list_keys_stream(&self, _bucket: &[u8]) -> DatastoreByteStream
fn list_keys_stream(&self, _bucket: &[u8]) -> DatastoreByteStream
Stream every key in bucket, one bytes::Bytes per key.
Same default as Datastore::list_buckets_stream: a
single-item stream carrying DatastoreError::Unsupported.
Sourcefn riak_get<'a>(
&'a self,
_bucket: &'a [u8],
_key: &'a [u8],
) -> BoxFuture<'a, Result<Option<Vec<u8>>, DatastoreError>>
fn riak_get<'a>( &'a self, _bucket: &'a [u8], _key: &'a [u8], ) -> BoxFuture<'a, Result<Option<Vec<u8>>, DatastoreError>>
Read the object stored under (bucket, key) against the
Riak K/V layer.
Returns Ok(None) when no object exists. The default
implementation reports the operation as unsupported so
existing Datastore impls that do not speak Riak
continue to compile against the new trait surface; the
PBC server treats the error as a routing failure and
emits an RpbErrorResp.
Sourcefn riak_put<'a>(
&'a self,
_bucket: &'a [u8],
_key: &'a [u8],
_value: &'a [u8],
_indexes: &'a [(Vec<u8>, Vec<u8>)],
) -> BoxFuture<'a, Result<(), DatastoreError>>
fn riak_put<'a>( &'a self, _bucket: &'a [u8], _key: &'a [u8], _value: &'a [u8], _indexes: &'a [(Vec<u8>, Vec<u8>)], ) -> BoxFuture<'a, Result<(), DatastoreError>>
Store value under (bucket, key). indexes carries
(index_name, encoded_value) pairs to associate with the
object on the 2i layer.
Default: unsupported, see Datastore::riak_get.
Sourcefn riak_delete<'a>(
&'a self,
_bucket: &'a [u8],
_key: &'a [u8],
) -> BoxFuture<'a, Result<bool, DatastoreError>>
fn riak_delete<'a>( &'a self, _bucket: &'a [u8], _key: &'a [u8], ) -> BoxFuture<'a, Result<bool, DatastoreError>>
Delete the object stored under (bucket, key). Returns
true when an object was removed, false when none
existed.
Default: unsupported, see Datastore::riak_get.
Sourcefn riak_index_eq<'a>(
&'a self,
_bucket: &'a [u8],
_index_name: &'a [u8],
_value: &'a [u8],
) -> BoxFuture<'a, Result<Vec<Vec<u8>>, DatastoreError>>
fn riak_index_eq<'a>( &'a self, _bucket: &'a [u8], _index_name: &'a [u8], _value: &'a [u8], ) -> BoxFuture<'a, Result<Vec<Vec<u8>>, DatastoreError>>
Equality query against the 2i layer.
Returns the object keys whose index_name value equals
value, ordered by the underlying storage’s natural key
order (typically lexicographic).
Default: unsupported, see Datastore::riak_get.
Sourcefn riak_index_range<'a>(
&'a self,
_bucket: &'a [u8],
_index_name: &'a [u8],
_min: &'a [u8],
_max: &'a [u8],
) -> BoxFuture<'a, Result<Vec<Vec<u8>>, DatastoreError>>
fn riak_index_range<'a>( &'a self, _bucket: &'a [u8], _index_name: &'a [u8], _min: &'a [u8], _max: &'a [u8], ) -> BoxFuture<'a, Result<Vec<Vec<u8>>, DatastoreError>>
Range query against the 2i layer. min and max are
inclusive bounds in the same encoding the index uses
internally.
Default: unsupported, see Datastore::riak_get.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".