Allow read_slice to return a Vec

This commit is contained in:
Julien Cretin
2022-06-03 11:16:43 +02:00
parent 85fe9cd29d
commit f57126634b
5 changed files with 29 additions and 24 deletions

View File

@@ -18,7 +18,7 @@
//! actual flash storage. Instead it uses a buffer in memory to represent the storage state.
use crate::{Storage, StorageError, StorageIndex, StorageResult};
use alloc::borrow::Borrow;
use alloc::borrow::{Borrow, Cow};
use alloc::boxed::Box;
use alloc::vec;
@@ -301,8 +301,8 @@ impl Storage for BufferStorage {
self.options.max_page_erases
}
fn read_slice(&self, index: StorageIndex, length: usize) -> StorageResult<&[u8]> {
Ok(&self.storage[index.range(length, self)?])
fn read_slice(&self, index: StorageIndex, length: usize) -> StorageResult<Cow<[u8]>> {
Ok(Cow::Borrowed(&self.storage[index.range(length, self)?]))
}
fn write_slice(&mut self, index: StorageIndex, value: &[u8]) -> StorageResult<()> {