Trait capsules_extra::tickv::KVSystem
source · pub trait KVSystem<'a> {
type K: KeyType;
// Required methods
fn set_client(&self, client: &'a dyn KVSystemClient<Self::K>);
fn generate_key(
&self,
unhashed_key: SubSliceMut<'static, u8>,
key_buf: &'static mut Self::K,
) -> Result<(), (SubSliceMut<'static, u8>, &'static mut Self::K, ErrorCode)>;
fn append_key(
&self,
key: &'static mut Self::K,
value: SubSliceMut<'static, u8>,
) -> Result<(), (&'static mut Self::K, SubSliceMut<'static, u8>, ErrorCode)>;
fn get_value(
&self,
key: &'static mut Self::K,
ret_buf: SubSliceMut<'static, u8>,
) -> Result<(), (&'static mut Self::K, SubSliceMut<'static, u8>, ErrorCode)>;
fn invalidate_key(
&self,
key: &'static mut Self::K,
) -> Result<(), (&'static mut Self::K, ErrorCode)>;
fn garbage_collect(&self) -> Result<(), ErrorCode>;
}
Required Associated Types§
Required Methods§
sourcefn set_client(&self, client: &'a dyn KVSystemClient<Self::K>)
fn set_client(&self, client: &'a dyn KVSystemClient<Self::K>)
Set the client.
sourcefn generate_key(
&self,
unhashed_key: SubSliceMut<'static, u8>,
key_buf: &'static mut Self::K,
) -> Result<(), (SubSliceMut<'static, u8>, &'static mut Self::K, ErrorCode)>
fn generate_key( &self, unhashed_key: SubSliceMut<'static, u8>, key_buf: &'static mut Self::K, ) -> Result<(), (SubSliceMut<'static, u8>, &'static mut Self::K, ErrorCode)>
Generate key.
unhashed_key
: A unhashed key that should be hashed.key_buf
: A buffer to store the hashed key output.
On success returns nothing.
On error the unhashed_key, key_buf and Result<(), ErrorCode>
will be returned.
sourcefn append_key(
&self,
key: &'static mut Self::K,
value: SubSliceMut<'static, u8>,
) -> Result<(), (&'static mut Self::K, SubSliceMut<'static, u8>, ErrorCode)>
fn append_key( &self, key: &'static mut Self::K, value: SubSliceMut<'static, u8>, ) -> Result<(), (&'static mut Self::K, SubSliceMut<'static, u8>, ErrorCode)>
Appends the key/value pair.
If the key already exists in the store and has not been invalidated then the append operation will fail. To update an existing key to a new value the key must first be invalidated.
key
: A hashed key. This key will be used in future to retrieve or remove thevalue
.value
: A buffer containing the data to be stored to flash.
On success nothing will be returned.
On error the key, value and a Result<(), ErrorCode>
will be returned.
The possible Result<(), ErrorCode>
s are:
BUSY
: An operation is already in progressINVAL
: An invalid parameter was passedNODEVICE
: No KV store was setupNOSUPPORT
: The key could not be added due to a collision.NOMEM
: The key could not be added due to no more space.
sourcefn get_value(
&self,
key: &'static mut Self::K,
ret_buf: SubSliceMut<'static, u8>,
) -> Result<(), (&'static mut Self::K, SubSliceMut<'static, u8>, ErrorCode)>
fn get_value( &self, key: &'static mut Self::K, ret_buf: SubSliceMut<'static, u8>, ) -> Result<(), (&'static mut Self::K, SubSliceMut<'static, u8>, ErrorCode)>
Retrieves the value from a specified key.
key
: A hashed key. This key will be used to retrieve thevalue
.ret_buf
: A buffer to store the value to.
On success nothing will be returned.
On error the key, ret_buf and a Result<(), ErrorCode>
will be returned.
The possible Result<(), ErrorCode>
s are:
BUSY
: An operation is already in progressINVAL
: An invalid parameter was passedNODEVICE
: No KV store was setupENOSUPPORT
: The key could not be found.SIZE
: The value is longer than the provided buffer.
sourcefn invalidate_key(
&self,
key: &'static mut Self::K,
) -> Result<(), (&'static mut Self::K, ErrorCode)>
fn invalidate_key( &self, key: &'static mut Self::K, ) -> Result<(), (&'static mut Self::K, ErrorCode)>
Invalidates the key in flash storage.
key
: A hashed key. This key will be used to remove thevalue
.
On success nothing will be returned.
On error the key and a Result<(), ErrorCode>
will be returned.
The possible Result<(), ErrorCode>
s are:
BUSY
: An operation is already in progressINVAL
: An invalid parameter was passedNODEVICE
: No KV store was setupENOSUPPORT
: The key could not be found.
sourcefn garbage_collect(&self) -> Result<(), ErrorCode>
fn garbage_collect(&self) -> Result<(), ErrorCode>
Perform a garbage collection on the KV Store.
For implementations that don’t require garbage collecting this should
return Err(ErrorCode::ALREADY)
.
On success nothing will be returned.
On error a Result<(), ErrorCode>
will be returned.
The possible ErrorCode
s are:
BUSY
: An operation is already in progress.ALREADY
: Nothing to be done. Callback will not trigger.INVAL
: An invalid parameter was passed.NODEVICE
: No KV store was setup.