Skip to content

Commit bf3e225

Browse files
committed
Make block size a parameter of BlockDevice trait.
1 parent 1d508c6 commit bf3e225

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/lib.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,10 @@ pub trait Storage: ReadStorage {
5454
fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error>;
5555
}
5656

57-
/// The size in bytes of a single block read or written by a [`BlockDevice`].
58-
pub const BLOCK_SIZE: usize = 512;
59-
60-
/// A single block which may be read or written by a [`BlockDevice`].
61-
///
62-
/// Also referred to as a sector in some contexts.
63-
pub type Block = [u8; BLOCK_SIZE];
64-
6557
/// A device which can read and write whole numbers of blocks.
66-
pub trait BlockDevice {
58+
///
59+
/// Blocks are also referred to as sectors in some contexts.
60+
pub trait BlockDevice<const BLOCK_SIZE: usize = 512> {
6761
/// The error type returned by methods on this trait.
6862
type Error;
6963

@@ -74,11 +68,19 @@ pub trait BlockDevice {
7468
///
7569
/// `first_block_index + blocks.len()` must not be greater than the size returned by
7670
/// `block_count`.
77-
fn read(&mut self, first_block_index: u64, blocks: &mut [Block]) -> Result<(), Self::Error>;
71+
fn read(
72+
&mut self,
73+
first_block_index: u64,
74+
blocks: &mut [[u8; BLOCK_SIZE]],
75+
) -> Result<(), Self::Error>;
7876

7977
/// Writes some number of blocks to the device, starting at `first_block_index`.
8078
///
8179
/// `first_block_index + blocks.len()` must not be greater than the size returned by
8280
/// `block_count`.
83-
fn write(&mut self, first_block_index: u64, blocks: &[Block]) -> Result<(), Self::Error>;
81+
fn write(
82+
&mut self,
83+
first_block_index: u64,
84+
blocks: &[[u8; BLOCK_SIZE]],
85+
) -> Result<(), Self::Error>;
8486
}

0 commit comments

Comments
 (0)