Skip to main content

KvStore

Trait KvStore 

Source
pub trait KvStore {
    // Required methods
    fn get(
        &self,
        key: &str,
        out: &mut [u8],
    ) -> impl Future<Output = Result<Option<usize>>>;
    fn set(&self, key: &str, value: &[u8]) -> impl Future<Output = Result<()>>;
    fn remove(&self, key: &str) -> impl Future<Output = Result<()>>;
    fn remove_prefix(&self, prefix: &str) -> impl Future<Output = Result<()>>;
}
Expand description

Non-volatile storage, as opaque blobs under string keys.

The store never sees a Matter type: this crate serialises everything itself, prefixes each blob with a schema version, and treats an unknown newer version as a failure rather than a value to guess at. That keeps the platform’s job to five methods and keeps migrations in one place.

Required Methods§

Source

fn get( &self, key: &str, out: &mut [u8], ) -> impl Future<Output = Result<Option<usize>>>

Reads the value of key into out, returning how many octets it holds.

Returns Ok(None) when the key is absent — which is not an error, it is how a factory-fresh node reads every key.

Source

fn set(&self, key: &str, value: &[u8]) -> impl Future<Output = Result<()>>

Writes value to key, replacing what was there.

Source

fn remove(&self, key: &str) -> impl Future<Output = Result<()>>

Removes key. Removing an absent key succeeds.

Source

fn remove_prefix(&self, prefix: &str) -> impl Future<Output = Result<()>>

Removes every key with the given prefix.

This is what RemoveFabric and a factory reset are built from.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl KvStore for FileKv

Available on crate feature std only.
Source§

impl KvStore for SimKv