embassy-usb

Crates

git

Versions

default

Flavors

Skip to main content

AsyncBlockDevice

Trait AsyncBlockDevice 

Source
pub trait AsyncBlockDevice {
    type Error;

    // Required methods
    fn block_size(&self) -> u32;
    fn block_count(&self) -> u32;
    async fn read_blocks(
        &mut self,
        lba: u32,
        buf: &mut [u8],
    ) -> Result<(), Self::Error>;
    async fn write_blocks(
        &mut self,
        lba: u32,
        data: &[u8],
    ) -> Result<(), Self::Error>;
    async fn flush(&mut self) -> Result<(), Self::Error>;

    // Provided method
    fn is_write_protected(&self) -> bool { ... }
}
Expand description

Async block device abstraction used by MscClass.

You can implement this trait directly for asynchronous storage, or implement BlockDevice and rely on the blanket adapter.

Required Associated Types§

Source

type Error

Error type returned by storage operations.

Required Methods§

Source

fn block_size(&self) -> u32

Returns the block size in bytes.

Source

fn block_count(&self) -> u32

Returns the total amount of logical blocks.

Source

async fn read_blocks( &mut self, lba: u32, buf: &mut [u8], ) -> Result<(), Self::Error>

Reads consecutive logical blocks starting at lba into buf.

buf.len() is a non-zero multiple of self.block_size(). Transferring several blocks per call lets storage use multi-block commands.

Source

async fn write_blocks( &mut self, lba: u32, data: &[u8], ) -> Result<(), Self::Error>

Writes consecutive logical blocks starting at lba from data.

data.len() is a non-zero multiple of self.block_size().

Source

async fn flush(&mut self) -> Result<(), Self::Error>

Flushes pending writes to backing storage.

Provided Methods§

Source

fn is_write_protected(&self) -> bool

Returns whether the media is write-protected.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<'a, D: AsyncBlockDevice> AsyncBlockDevice for SectorCache<'a, D>

Source§

impl<B: BlockDevice<SIZE>, const SIZE: usize> AsyncBlockDevice for BlockDeviceAdapter<B, SIZE>

Available on crate feature block-device-driver only.
Source§

type Error = <B as BlockDevice<SIZE>>::Error

Source§

impl<T: BlockDevice + ?Sized> AsyncBlockDevice for T