diff --git a/src/persist.rs b/src/persist.rs index 12c08ad..a2d1b58 100644 --- a/src/persist.rs +++ b/src/persist.rs @@ -5,7 +5,7 @@ use log::info; use rs_matter::error::{Error, ErrorCode}; -use rs_matter_stack::persist::{KvBlobStore, KvPersist}; +use rs_matter_stack::persist::{Key, KvBlobStore, KvPersist}; pub type EspMatterPersist<'a, T, C> = KvPersist<'a, EspKvBlobStore, C>; @@ -31,10 +31,10 @@ where Ok(Self(EspNvs::new(nvs, namespace, true)?)) } - fn load_blob<'b>(&self, key: &str, buf: &'b mut [u8]) -> Result, EspError> { + fn load_blob<'b>(&self, key: Key, buf: &'b mut [u8]) -> Result, EspError> { // TODO: Not really async - let data = self.0.get_blob(key, buf)?; + let data = self.0.get_blob(key.as_ref(), buf)?; info!( "Blob {key}: loaded {:?} bytes {data:?}", data.map(|data| data.len()) @@ -43,20 +43,20 @@ where Ok(data) } - fn store_blob(&mut self, key: &str, data: &[u8]) -> Result<(), EspError> { + fn store_blob(&mut self, key: Key, data: &[u8]) -> Result<(), EspError> { // TODO: Not really async - self.0.set_blob(key, data)?; + self.0.set_blob(key.as_ref(), data)?; info!("Blob {key}: stored {} bytes {data:?}", data.len()); Ok(()) } - fn remove_blob(&mut self, key: &str) -> Result<(), EspError> { + fn remove_blob(&mut self, key: Key) -> Result<(), EspError> { // TODO: Not really async - self.0.remove(key)?; + self.0.remove(key.as_ref())?; info!("Blob {key}: removed"); @@ -68,20 +68,20 @@ impl KvBlobStore for EspKvBlobStore where T: NvsPartitionId, { - async fn load<'a>(&mut self, key: &str, buf: &'a mut [u8]) -> Result, Error> { + async fn load<'a>(&mut self, key: Key, buf: &'a mut [u8]) -> Result, Error> { Ok(self .load_blob(key, buf) .map_err(|_| ErrorCode::StdIoError)?) // TODO: We need a dedicated PersistError code here } - async fn store(&mut self, key: &str, value: &[u8]) -> Result<(), Error> { + async fn store(&mut self, key: Key, value: &[u8]) -> Result<(), Error> { self.store_blob(key, value) .map_err(|_| ErrorCode::StdIoError)?; Ok(()) } - async fn remove(&mut self, key: &str) -> Result<(), Error> { + async fn remove(&mut self, key: Key) -> Result<(), Error> { self.remove_blob(key).map_err(|_| ErrorCode::StdIoError)?; Ok(())