Skip to content

Commit

Permalink
driver::Storage::read(&self -> &mut self)
Browse files Browse the repository at this point in the history
The definition with an immutable self clashes with the ReadNorFlash trait
from the embedded_storage crate which has read(&mut self, ...). Allowing
the object to be mutated is more generic, so change our Storage trait
accordingly.
  • Loading branch information
Jan Nordholz authored and daringer committed Jul 4, 2022
1 parent 3110912 commit 50a634c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub trait Storage {

/// Read data from the storage device.
/// Guaranteed to be called only with bufs of length a multiple of READ_SIZE.
fn read(&self, off: usize, buf: &mut [u8]) -> Result<usize>;
fn read(&mut self, off: usize, buf: &mut [u8]) -> Result<usize>;
/// Write data to the storage device.
/// Guaranteed to be called only with bufs of length a multiple of WRITE_SIZE.
fn write(&mut self, off: usize, data: &[u8]) -> Result<usize>;
Expand Down
2 changes: 1 addition & 1 deletion src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ impl<Storage: driver::Storage> Filesystem<'_, Storage> {
size: ll::lfs_size_t,
) -> cty::c_int {
// println!("in lfs_config_read for {} bytes", size);
let storage = unsafe { &*((*c).context as *const Storage) };
let storage = unsafe { &mut *((*c).context as *mut Storage) };
debug_assert!(!c.is_null());
let block_size = unsafe { c.read().block_size };
let off = (block * block_size + off) as usize;
Expand Down
4 changes: 2 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ macro_rules! ram_storage { (
const BLOCK_COUNT: usize = $block_count;
type LOOKAHEADWORDS_SIZE = $lookaheadwords_size;

fn read(&self, offset: usize, buf: &mut [u8]) -> $Result<usize> {
fn read(&mut self, offset: usize, buf: &mut [u8]) -> $Result<usize> {
let read_size: usize = Self::READ_SIZE;
debug_assert!(offset % read_size == 0);
debug_assert!(buf.len() % read_size == 0);
Expand Down Expand Up @@ -180,7 +180,7 @@ macro_rules! const_ram_storage { (
const BLOCK_COUNT: usize = $block_count;
type LOOKAHEADWORDS_SIZE = $lookaheadwords_size;

fn read(&self, offset: usize, buf: &mut [u8]) -> $Result<usize> {
fn read(&mut self, offset: usize, buf: &mut [u8]) -> $Result<usize> {
let read_size: usize = Self::READ_SIZE;
debug_assert!(offset % read_size == 0);
debug_assert!(buf.len() % read_size == 0);
Expand Down

0 comments on commit 50a634c

Please sign in to comment.