diff --git a/src/device.rs b/src/device.rs index 887221e..cb2621f 100644 --- a/src/device.rs +++ b/src/device.rs @@ -106,7 +106,7 @@ impl Seek for StreamSlice { /// A Stream wrapper for accessing a stream in block sized chunks. /// -/// [`BlockAccess Seek for StreamSlice { /// - `buf.len()` has the same alignment as the internal buffer /// #[derive(Clone)] -pub struct BlockAccess +pub struct BlockDevice where Align: Alignment, { inner: T, buffer: AlignedBuffer, - last_block: u64, + current_block: u64, } #[derive(Clone)] @@ -169,14 +169,14 @@ where } } -impl BlockAccess +impl BlockDevice where Align: Alignment, { pub const fn new(inner: T) -> Self { Self { inner, - last_block: u64::MAX, + current_block: u64::MAX, buffer: AlignedBuffer::new(), } } @@ -188,14 +188,14 @@ where } impl embedded_io::ErrorType - for BlockAccess + for BlockDevice where Align: Alignment, { type Error = T::Error; } -impl Read for BlockAccess +impl Read for BlockDevice where Align: Alignment, T::Error: From> + From>, @@ -211,7 +211,7 @@ where let block_end = block_start + SIZE as u64; log::info!("offset {offset}, block_start {block_start}, block_end {block_end}"); - if block_start != self.last_block { + if block_start != self.current_block { // We have seeked to a new block, read it self.inner.seek(io::SeekFrom::Start(block_start)).await?; self.inner.read_exact(&mut self.buffer[..]).await?; @@ -232,7 +232,7 @@ where } } -impl Write for BlockAccess +impl Write for BlockDevice where Align: Alignment, T::Error: From> + From>, @@ -248,7 +248,7 @@ where let block_end = block_start + SIZE as u64; log::info!("offset {offset}, block_start {block_start}, block_end {block_end}"); - if block_start != self.last_block { + if block_start != self.current_block { // We have seeked to a new block, read it self.inner.seek(io::SeekFrom::Start(block_start)).await?; self.inner.read_exact(&mut self.buffer[..]).await?; @@ -279,7 +279,7 @@ where } } -impl Seek for BlockAccess +impl Seek for BlockDevice where Align: Alignment, { @@ -290,7 +290,7 @@ where #[cfg(test)] mod tests { - use super::{BlockAccess, *}; + use super::{BlockDevice, *}; #[tokio::test] async fn stream_smoke_test() { @@ -321,7 +321,7 @@ mod tests { let _ = env_logger::builder().is_test(true).try_init(); let buf = ("A".repeat(512) + "B".repeat(512).as_str()).into_bytes(); let cur = std::io::Cursor::new(buf); - let mut block: BlockAccess<_, 512, 4> = BlockAccess::new(embedded_io_adapters::tokio_1::FromTokio::new(cur)); + let mut block: BlockDevice<_, 512, 4> = BlockDevice::new(embedded_io_adapters::tokio_1::FromTokio::new(cur)); // Test sector aligned access let mut buf = vec![0; 128]; @@ -346,7 +346,7 @@ mod tests { let _ = env_logger::builder().is_test(true).try_init(); let buf = ("A".repeat(64) + "B".repeat(64).as_str()).repeat(16).into_bytes(); let cur = std::io::Cursor::new(buf); - let mut block: BlockAccess<_, 512, 4> = BlockAccess::new(embedded_io_adapters::tokio_1::FromTokio::new(cur)); + let mut block: BlockDevice<_, 512, 4> = BlockDevice::new(embedded_io_adapters::tokio_1::FromTokio::new(cur)); // Test sector aligned access let mut buf = vec![0; 64]; @@ -370,7 +370,7 @@ mod tests { let _ = env_logger::builder().is_test(true).try_init(); let buf = vec![0; 2048]; let cur = std::io::Cursor::new(buf); - let mut block: BlockAccess<_, 512, 4> = BlockAccess::new(embedded_io_adapters::tokio_1::FromTokio::new(cur)); + let mut block: BlockDevice<_, 512, 4> = BlockDevice::new(embedded_io_adapters::tokio_1::FromTokio::new(cur)); // Test sector aligned access let data_a = "A".repeat(512).into_bytes(); @@ -384,7 +384,7 @@ mod tests { let _ = env_logger::builder().is_test(true).try_init(); let buf = vec![0; 2048]; let cur = std::io::Cursor::new(buf); - let mut block: BlockAccess<_, 512, 4> = BlockAccess::new(embedded_io_adapters::tokio_1::FromTokio::new(cur)); + let mut block: BlockDevice<_, 512, 4> = BlockDevice::new(embedded_io_adapters::tokio_1::FromTokio::new(cur)); // Test sector aligned access let data_a = "A".repeat(512).into_bytes(); @@ -401,7 +401,7 @@ mod tests { let _ = env_logger::builder().is_test(true).try_init(); let buf = vec![0; 2048]; let cur = std::io::Cursor::new(buf); - let mut block: BlockAccess<_, 512, 4> = BlockAccess::new(embedded_io_adapters::tokio_1::FromTokio::new(cur)); + let mut block: BlockDevice<_, 512, 4> = BlockDevice::new(embedded_io_adapters::tokio_1::FromTokio::new(cur)); let mut aligned_buffer: AlignedBuffer<2048, 4> = AlignedBuffer::new(); let data_a = "A".repeat(512).into_bytes(); @@ -420,7 +420,7 @@ mod tests { let _ = env_logger::builder().is_test(true).try_init(); let buf = "A".repeat(2048).into_bytes(); let cur = std::io::Cursor::new(buf); - let mut block: BlockAccess<_, 512, 4> = BlockAccess::new(embedded_io_adapters::tokio_1::FromTokio::new(cur)); + let mut block: BlockDevice<_, 512, 4> = BlockDevice::new(embedded_io_adapters::tokio_1::FromTokio::new(cur)); let mut aligned_buffer: AlignedBuffer<512, 4> = AlignedBuffer::new(); block.seek(io::SeekFrom::Start(0)).await.unwrap();