Skip to content

Commit 309bdbc

Browse files
committed
Make it easier to integrate sequential_map downstream
1 parent 93ebab5 commit 309bdbc

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

rs-matter/src/persist.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,23 @@ pub trait KvBlobStore {
6262
/// # Arguments
6363
/// - `key` - the key of the BLOB
6464
/// - `data` - the data to store
65+
/// - `buf` - a buffer that the `KvBlobStore` implementation might use for its own purposes
6566
///
6667
/// # Returns
6768
/// - `Ok(())` if the BLOB was successfully stored,
6869
/// - `Err` if an error occurred during storing.
69-
async fn store(&mut self, key: u16, data: &[u8]) -> Result<(), Error>;
70+
async fn store(&mut self, key: u16, data: &[u8], buf: &mut [u8]) -> Result<(), Error>;
7071

7172
/// Remove a BLOB with the specified key from the storage.
7273
///
7374
/// # Arguments
7475
/// - `key` - the key of the BLOB
76+
/// - `buf` - a buffer that the `KvBlobStore` implementation might use for its own purposes
7577
///
7678
/// # Returns
7779
/// - `Ok(())` if the BLOB was successfully removed or did not exist
7880
/// - `Err` if an error occurred during removing.
79-
async fn remove(&mut self, key: u16) -> Result<(), Error>;
81+
async fn remove(&mut self, key: u16, buf: &mut [u8]) -> Result<(), Error>;
8082
}
8183

8284
impl<T> KvBlobStore for &mut T
@@ -87,12 +89,12 @@ where
8789
T::load(self, key, buf).await
8890
}
8991

90-
async fn store(&mut self, key: u16, data: &[u8]) -> Result<(), Error> {
91-
T::store(self, key, data).await
92+
async fn store(&mut self, key: u16, data: &[u8], buf: &mut [u8]) -> Result<(), Error> {
93+
T::store(self, key, data, buf).await
9294
}
9395

94-
async fn remove(&mut self, key: u16) -> Result<(), Error> {
95-
T::remove(self, key).await
96+
async fn remove(&mut self, key: u16, buf: &mut [u8]) -> Result<(), Error> {
97+
T::remove(self, key, buf).await
9698
}
9799
}
98100

@@ -104,11 +106,11 @@ impl KvBlobStore for DummyKvBlobStore {
104106
Ok(None)
105107
}
106108

107-
async fn store(&mut self, _key: u16, _data: &[u8]) -> Result<(), Error> {
109+
async fn store(&mut self, _key: u16, _data: &[u8], _buf: &mut [u8]) -> Result<(), Error> {
108110
Ok(())
109111
}
110112

111-
async fn remove(&mut self, _key: u16) -> Result<(), Error> {
113+
async fn remove(&mut self, _key: u16, _buf: &mut [u8]) -> Result<(), Error> {
112114
Ok(())
113115
}
114116
}
@@ -300,10 +302,12 @@ where
300302
let (mut kv, buf) = self.kvb.split();
301303

302304
if let Some(key) = self.key {
305+
let (data, buf) = buf.split_at_mut(self.len);
306+
303307
if self.len > 0 {
304-
kv.store(key, &buf[..self.len]).await?;
308+
kv.store(key, data, buf).await?;
305309
} else {
306-
kv.remove(key).await?;
310+
kv.remove(key, buf).await?;
307311
}
308312
}
309313

@@ -420,11 +424,11 @@ mod fileio {
420424
Self::load(self, key, buf)
421425
}
422426

423-
async fn store(&mut self, key: u16, data: &[u8]) -> Result<(), Error> {
427+
async fn store(&mut self, key: u16, data: &[u8], _buf: &mut [u8]) -> Result<(), Error> {
424428
Self::store(self, key, data)
425429
}
426430

427-
async fn remove(&mut self, key: u16) -> Result<(), Error> {
431+
async fn remove(&mut self, key: u16, _buf: &mut [u8]) -> Result<(), Error> {
428432
Self::remove(self, key)
429433
}
430434
}
@@ -559,11 +563,11 @@ mod fileio {
559563
Self::load(self, key, buf)
560564
}
561565

562-
async fn store(&mut self, key: u16, data: &[u8]) -> Result<(), Error> {
566+
async fn store(&mut self, key: u16, data: &[u8], _buf: &mut [u8]) -> Result<(), Error> {
563567
Self::store(self, key, data)
564568
}
565569

566-
async fn remove(&mut self, key: u16) -> Result<(), Error> {
570+
async fn remove(&mut self, key: u16, _buf: &mut [u8]) -> Result<(), Error> {
567571
Self::remove(self, key)
568572
}
569573
}

0 commit comments

Comments
 (0)