pub trait KVStore: KVStorePersister {
type Reader: Read;
// Required methods
fn read(&self, namespace: &str, key: &str) -> Result<Self::Reader>;
fn write(&self, namespace: &str, key: &str, buf: &[u8]) -> Result<()>;
fn remove(&self, namespace: &str, key: &str) -> Result<bool>;
fn list(&self, namespace: &str) -> Result<Vec<String>>;
}
Expand description
Provides an interface that allows to store and retrieve persisted values that are associated with given keys.
In order to avoid collisions the key space is segmented based on the given namespace
s.
Implementations of this trait are free to handle them in different ways, as long as
per-namespace key uniqueness is asserted.
Keys and namespaces are required to be valid ASCII strings and the empty namespace (""
) is
assumed to be valid namespace.
Required Associated Types§
Required Methods§
sourcefn read(&self, namespace: &str, key: &str) -> Result<Self::Reader>
fn read(&self, namespace: &str, key: &str) -> Result<Self::Reader>
Returns a Read
for the given namespace
and key
from which Readable
s may be
read.
Returns an ErrorKind::NotFound
if the given key
could not be found in the given namespace
.
sourcefn write(&self, namespace: &str, key: &str, buf: &[u8]) -> Result<()>
fn write(&self, namespace: &str, key: &str, buf: &[u8]) -> Result<()>
Persists the given data under the given key
.
Will create the given namespace
if not already present in the store.