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
: Thealigned::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§
Required Methods§
Sourceasync fn read(
&mut self,
block_address: u32,
data: &mut [Aligned<Self::Align, [u8; SIZE]>],
) -> Result<(), Self::Error>
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.
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.