Skip to content

Commit 71d15ab

Browse files
committed
BlockDevice: impl for types that deref into BlockDevice
1 parent 99c11dc commit 71d15ab

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/sdmmc.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use super::sdmmc_proto::*;
99
use super::{Block, BlockCount, BlockDevice, BlockIdx};
1010
use core::cell::RefCell;
11+
use core::ops::Deref;
1112

1213
#[cfg(feature = "log")]
1314
use log::{debug, trace, warn};
@@ -487,6 +488,27 @@ where
487488
}
488489
}
489490

491+
impl<U: BlockDevice, T: Deref<Target = U>> BlockDevice for T {
492+
type Error = U::Error;
493+
fn read(
494+
&self,
495+
blocks: &mut [Block],
496+
start_block_idx: BlockIdx,
497+
_reason: &str,
498+
) -> Result<(), Self::Error> {
499+
self.deref().read(blocks, start_block_idx, _reason)
500+
}
501+
502+
/// Write one or more blocks, starting at the given block index.
503+
fn write(&self, blocks: &[Block], start_block_idx: BlockIdx) -> Result<(), Self::Error> {
504+
self.deref().write(blocks, start_block_idx)
505+
}
506+
507+
fn num_blocks(&self) -> Result<BlockCount, Self::Error> {
508+
self.deref().num_blocks()
509+
}
510+
}
511+
490512
impl<SPI, CS> BlockDevice for BlockSpi<'_, SPI, CS>
491513
where
492514
SPI: embedded_hal::blocking::spi::Transfer<u8>,

0 commit comments

Comments
 (0)