pub const BLOCK_SIZE: usize = 512;
pub trait BlockDevice {
type Error;
async fn read_block(
&mut self,
block: u32,
buffer: &mut [u8; BLOCK_SIZE],
) -> Result<(), Self::Error>;
async fn num_blocks(&mut self) -> Result<u32, Self::Error>;
}
#[cfg(feature = "write")]
pub trait BlockWrite: BlockDevice {
async fn write_block(
&mut self,
block: u32,
buffer: &[u8; BLOCK_SIZE],
) -> Result<(), Self::Error>;
}
#[cfg(feature = "write")]
impl<D: BlockWrite + ?Sized> BlockWrite for &mut D {
async fn write_block(
&mut self,
block: u32,
buffer: &[u8; BLOCK_SIZE],
) -> Result<(), Self::Error> {
(**self).write_block(block, buffer).await
}
}
impl<D: BlockDevice + ?Sized> BlockDevice for &mut D {
type Error = D::Error;
async fn read_block(
&mut self,
block: u32,
buffer: &mut [u8; BLOCK_SIZE],
) -> Result<(), Self::Error> {
(**self).read_block(block, buffer).await
}
async fn num_blocks(&mut self) -> Result<u32, Self::Error> {
(**self).num_blocks().await
}
}