Trait ldk_node::io::KVStore

source ·
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 namespaces. 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§

source

fn read(&self, namespace: &str, key: &str) -> Result<Self::Reader>

Returns a Read for the given namespace and key from which Readables may be read.

Returns an ErrorKind::NotFound if the given key could not be found in the given namespace.

source

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.

source

fn remove(&self, namespace: &str, key: &str) -> Result<bool>

Removes any data that had previously been persisted under the given key.

Returns true if the key was present in the given namespace, and false otherwise.

source

fn list(&self, namespace: &str) -> Result<Vec<String>>

Returns a list of keys that are stored under the given namespace.

Will return an empty list if the namespace is unknown.

Implementors§