Trait BlockDevice

Source
pub trait BlockDevice<const SIZE: usize> {
    type Error: Debug;
    type Align: Alignment;

    // Required methods
    async fn read(
        &mut self,
        block_address: u32,
        data: &mut [Aligned<Self::Align, [u8; SIZE]>],
    ) -> Result<(), Self::Error>;
    async fn write(
        &mut self,
        block_address: u32,
        data: &[Aligned<Self::Align, [u8; SIZE]>],
    ) -> Result<(), Self::Error>;
    async fn size(&mut self) -> Result<u64, Self::Error>;
}
Expand description

A trait for a block devices

BlockDevice<const SIZE: usize> can be initialized with the following parameters.

  • const SIZE: The size of the block in the block device.
  • type Align: The aligned::Alignment of the block buffers for this implementation.
  • type Error: The error type for the implementation.

The generic parameter SIZE on BlockDevice is the number of bytes in a block for this block device.

All addresses are zero indexed, and the unit is blocks. For example to read bytes from 1024 to 1536 on a 512 byte block device, the supplied block address would be 2.

NOTE to implementors: Alignment of the buffer must be multiple of SIZE to avoid padding bytes when casting between blocks and slices.

This trait can be implemented multiple times to support various different block sizes.

Required Associated Types§

Source

type Error: Debug

The error type for the BlockDevice implementation.

Source

type Align: Alignment

The alignment requirements of the block buffers.

Required Methods§

Source

async fn read( &mut self, block_address: u32, data: &mut [Aligned<Self::Align, [u8; SIZE]>], ) -> Result<(), Self::Error>

Read one or more blocks at the given block address.

Source

async fn write( &mut self, block_address: u32, data: &[Aligned<Self::Align, [u8; SIZE]>], ) -> Result<(), Self::Error>

Write one or more blocks at the given block address.

Source

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

Report the size of the block device in bytes.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: BlockDevice<SIZE>, const SIZE: usize> BlockDevice<SIZE> for &mut T

Source§

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

Source§

type Align = <T as BlockDevice<SIZE>>::Align

Source§

async fn read( &mut self, block_address: u32, data: &mut [Aligned<Self::Align, [u8; SIZE]>], ) -> Result<(), Self::Error>

Source§

async fn write( &mut self, block_address: u32, data: &[Aligned<Self::Align, [u8; SIZE]>], ) -> Result<(), Self::Error>

Source§

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

Implementors§