Skip to content

Commit

Permalink
update to eio 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
MabezDev committed Oct 12, 2023
1 parent b05b930 commit 3b5bb06
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 363 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ default = ["chrono", "std", "alloc", "lfn", "unicode", "log"]
[dependencies]
# core deps
bitflags = "1.0"
embedded-io-async = "0.5"
embedded-io-async = "0.6"
async-iterator = { version = "2.1", default-features = false }

# optional deps
embedded-io-adapters = { version = "0.5", package = "embedded-io-adapters", features = ["tokio-1"], optional = true }
embedded-io-adapters = { version = "0.6", package = "embedded-io-adapters", features = ["tokio-1"], optional = true }
chrono = { version = "0.4", default-features = false, features = ["clock"], optional = true }
tokio = { version = "1", default-features = false, optional = true }
elain = { version = "0.3", optional = true }
Expand Down
19 changes: 4 additions & 15 deletions src/boot_sector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use core::cmp;
use core::u16;
use core::u8;

use embedded_io_async::WriteAllError;

use crate::dir_entry::DIR_ENTRY_SIZE;
use crate::error::{Error, IoError, ReadExactError};
use crate::fs::{FatType, FormatVolumeOptions, FsStatusFlags};
Expand Down Expand Up @@ -49,10 +47,7 @@ pub(crate) struct BiosParameterBlock {
}

impl BiosParameterBlock {
async fn deserialize<R: Read>(rdr: &mut R) -> Result<Self, R::Error>
where
R::Error: From<ReadExactError<R::Error>>,
{
async fn deserialize<R: Read>(rdr: &mut R) -> Result<Self, Error<R::Error>> {
let mut bpb = Self {
bytes_per_sector: rdr.read_u16_le().await?,
sectors_per_cluster: rdr.read_u8().await?,
Expand Down Expand Up @@ -97,10 +92,7 @@ impl BiosParameterBlock {
Ok(bpb)
}

async fn serialize<W: Write>(&self, wrt: &mut W) -> Result<(), W::Error>
where
W::Error: From<WriteAllError<W::Error>>,
{
async fn serialize<W: Write>(&self, wrt: &mut W) -> Result<(), W::Error> {
wrt.write_u16_le(self.bytes_per_sector).await?;
wrt.write_u8(self.sectors_per_cluster).await?;
wrt.write_u16_le(self.reserved_sectors).await?;
Expand Down Expand Up @@ -429,7 +421,7 @@ pub(crate) struct BootSector {
}

impl BootSector {
pub(crate) async fn deserialize<R: Read>(rdr: &mut R) -> Result<Self, R::Error>
pub(crate) async fn deserialize<R: Read>(rdr: &mut R) -> Result<Self, Error<R::Error>>
where
R::Error: From<ReadExactError<R::Error>>,
{
Expand All @@ -447,10 +439,7 @@ impl BootSector {
Ok(boot)
}

pub(crate) async fn serialize<W: Write>(&self, wrt: &mut W) -> Result<(), W::Error>
where
W::Error: From<WriteAllError<W::Error>>,
{
pub(crate) async fn serialize<W: Write>(&self, wrt: &mut W) -> Result<(), W::Error> {
wrt.write_all(&self.bootjmp).await?;
wrt.write_all(&self.oem_name).await?;
self.bpb.serialize(&mut *wrt).await?;
Expand Down
22 changes: 1 addition & 21 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use core::cmp;
use core::fmt::Debug;
use elain::{Align, Alignment};
use embedded_io_async::{Read, ReadExactError, Seek, SeekFrom, Write, WriteAllError};
use embedded_io_async::{Read, ReadExactError, Seek, SeekFrom, Write};

Check warning on line 6 in src/device.rs

View workflow job for this annotation

GitHub Actions / Build (nightly, true)

unused import: `ReadExactError`

Check warning on line 6 in src/device.rs

View workflow job for this annotation

GitHub Actions / Build (nightly, true)

unused import: `ReadExactError`

#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug)]
Expand All @@ -20,24 +20,6 @@ impl<E: Debug> From<E> for StreamSliceError<E> {
}
}

impl<E: Debug> From<WriteAllError<StreamSliceError<E>>> for StreamSliceError<E> {
fn from(e: WriteAllError<StreamSliceError<E>>) -> Self {
match e {
WriteAllError::WriteZero => Self::WriteZero,
WriteAllError::Other(e) => e,
}
}
}

impl<E: Debug> From<ReadExactError<StreamSliceError<E>>> for StreamSliceError<E> {
fn from(e: ReadExactError<StreamSliceError<E>>) -> Self {
match e {
ReadExactError::UnexpectedEof => Self::UnexpectedEof,
ReadExactError::Other(e) => e,
}
}
}

/// Stream wrapper for accessing limited segment of data from underlying file or device.
#[derive(Clone)]
pub struct StreamSlice<T: Read + Write + Seek> {
Expand Down Expand Up @@ -189,7 +171,6 @@ where
impl<T: Device<SIZE>, const SIZE: usize, const ALIGN: usize> Read for BlockDevice<T, SIZE, ALIGN>
where
Align<ALIGN>: Alignment,
T::Error: From<ReadExactError<T::Error>> + From<WriteAllError<T::Error>>,
{
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, T::Error> {
Ok(if buf.len() % SIZE == 0 && &buf[0] as *const _ as usize % ALIGN == 0 {
Expand Down Expand Up @@ -231,7 +212,6 @@ where
impl<T: Device<SIZE>, const SIZE: usize, const ALIGN: usize> Write for BlockDevice<T, SIZE, ALIGN>
where
Align<ALIGN>: Alignment,
T::Error: From<ReadExactError<T::Error>> + From<WriteAllError<T::Error>>,
{
async fn write(&mut self, buf: &[u8]) -> Result<usize, T::Error> {
Ok(if buf.len() % SIZE == 0 && &buf[0] as *const _ as usize % ALIGN == 0 {
Expand Down
86 changes: 17 additions & 69 deletions src/dir.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[cfg(all(not(feature = "std"), feature = "alloc", feature = "lfn"))]
use alloc::vec::Vec;
use embedded_io_async::ReadExactError;

Check warning on line 3 in src/dir.rs

View workflow job for this annotation

GitHub Actions / Build (nightly, true)

unused import: `embedded_io_async::ReadExactError`

Check warning on line 3 in src/dir.rs

View workflow job for this annotation

GitHub Actions / Build (nightly, true)

unused import: `embedded_io_async::ReadExactError`

Check warning on line 3 in src/dir.rs

View workflow job for this annotation

GitHub Actions / Build (nightly, true)

unused import: `embedded_io_async::ReadExactError`

Check warning on line 3 in src/dir.rs

View workflow job for this annotation

GitHub Actions / Build (nightly, true)

unused import: `embedded_io_async::ReadExactError`
use embedded_io_async::WriteAllError;

use core::char;
use core::cmp;
Expand All @@ -25,18 +24,12 @@ use async_iterator::Iterator as AsyncIterator;

const LFN_PADDING: u16 = 0xFFFF;

pub(crate) enum DirRawStream<'a, IO: ReadWriteSeek, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
pub(crate) enum DirRawStream<'a, IO: ReadWriteSeek, TP, OCC> {
File(File<'a, IO, TP, OCC>),
Root(DiskSlice<FsIoAdapter<'a, IO, TP, OCC>, FsIoAdapter<'a, IO, TP, OCC>>),
}

impl<IO: ReadWriteSeek, TP, OCC> DirRawStream<'_, IO, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
impl<IO: ReadWriteSeek, TP, OCC> DirRawStream<'_, IO, TP, OCC> {
fn abs_pos(&self) -> Option<u64> {
match self {
DirRawStream::File(file) => file.abs_pos(),
Expand All @@ -53,10 +46,7 @@ where
}

// Note: derive cannot be used because of invalid bounds. See: https://github.com/rust-lang/rust/issues/26925
impl<IO: ReadWriteSeek, TP, OCC> Clone for DirRawStream<'_, IO, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
impl<IO: ReadWriteSeek, TP, OCC> Clone for DirRawStream<'_, IO, TP, OCC> {
fn clone(&self) -> Self {
match self {
DirRawStream::File(file) => DirRawStream::File(file.clone()),
Expand All @@ -65,17 +55,11 @@ where
}
}

impl<IO: ReadWriteSeek, TP, OCC> IoBase for DirRawStream<'_, IO, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
impl<IO: ReadWriteSeek, TP, OCC> IoBase for DirRawStream<'_, IO, TP, OCC> {
type Error = Error<IO::Error>;
}

impl<IO: ReadWriteSeek, TP: TimeProvider, OCC> Read for DirRawStream<'_, IO, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
impl<IO: ReadWriteSeek, TP: TimeProvider, OCC> Read for DirRawStream<'_, IO, TP, OCC> {
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
match self {
DirRawStream::File(file) => file.read(buf).await,
Expand All @@ -84,10 +68,7 @@ where
}
}

impl<IO: ReadWriteSeek, TP: TimeProvider, OCC> Write for DirRawStream<'_, IO, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
impl<IO: ReadWriteSeek, TP: TimeProvider, OCC> Write for DirRawStream<'_, IO, TP, OCC> {
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
match self {
DirRawStream::File(file) => file.write(buf).await,
Expand All @@ -102,10 +83,7 @@ where
}
}

impl<IO: ReadWriteSeek, TP, OCC> Seek for DirRawStream<'_, IO, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
impl<IO: ReadWriteSeek, TP, OCC> Seek for DirRawStream<'_, IO, TP, OCC> {
async fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error> {
match self {
DirRawStream::File(file) => file.seek(pos).await,
Expand All @@ -121,10 +99,7 @@ fn split_path(path: &str) -> (&str, Option<&str>) {
})
}

enum DirEntryOrShortName<'a, IO: ReadWriteSeek, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
enum DirEntryOrShortName<'a, IO: ReadWriteSeek, TP, OCC> {
DirEntry(DirEntry<'a, IO, TP, OCC>),
ShortName([u8; SFN_SIZE]),
}
Expand All @@ -133,18 +108,12 @@ where
///
/// This struct is created by the `open_dir` or `create_dir` methods on `Dir`.
/// The root directory is returned by the `root_dir` method on `FileSystem`.
pub struct Dir<'a, IO: ReadWriteSeek, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
pub struct Dir<'a, IO: ReadWriteSeek, TP, OCC> {
stream: DirRawStream<'a, IO, TP, OCC>,
fs: &'a FileSystem<IO, TP, OCC>,
}

impl<'a, IO: ReadWriteSeek, TP, OCC> Dir<'a, IO, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
impl<'a, IO: ReadWriteSeek, TP, OCC> Dir<'a, IO, TP, OCC> {
pub(crate) fn new(stream: DirRawStream<'a, IO, TP, OCC>, fs: &'a FileSystem<IO, TP, OCC>) -> Self {
Dir { stream, fs }
}
Expand All @@ -157,10 +126,7 @@ where
}
}

impl<'a, IO: ReadWriteSeek, TP: TimeProvider, OCC: OemCpConverter> Dir<'a, IO, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
impl<'a, IO: ReadWriteSeek, TP: TimeProvider, OCC: OemCpConverter> Dir<'a, IO, TP, OCC> {
async fn find_entry(
&self,
name: &str,
Expand Down Expand Up @@ -724,10 +690,7 @@ where
}

// Note: derive cannot be used because of invalid bounds. See: https://github.com/rust-lang/rust/issues/26925
impl<IO: ReadWriteSeek, TP: TimeProvider, OCC: OemCpConverter> Clone for Dir<'_, IO, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
impl<IO: ReadWriteSeek, TP: TimeProvider, OCC: OemCpConverter> Clone for Dir<'_, IO, TP, OCC> {
fn clone(&self) -> Self {
Self {
stream: self.stream.clone(),
Expand All @@ -739,20 +702,14 @@ where
/// An iterator over the directory entries.
///
/// This struct is created by the `iter` method on `Dir`.
pub struct DirIter<'a, IO: ReadWriteSeek, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
pub struct DirIter<'a, IO: ReadWriteSeek, TP, OCC> {
stream: DirRawStream<'a, IO, TP, OCC>,
fs: &'a FileSystem<IO, TP, OCC>,
skip_volume: bool,
err: bool,
}

impl<'a, IO: ReadWriteSeek, TP, OCC> DirIter<'a, IO, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
impl<'a, IO: ReadWriteSeek, TP, OCC> DirIter<'a, IO, TP, OCC> {
fn new(stream: DirRawStream<'a, IO, TP, OCC>, fs: &'a FileSystem<IO, TP, OCC>, skip_volume: bool) -> Self {
DirIter {
stream,
Expand All @@ -763,10 +720,7 @@ where
}
}

impl<'a, IO: ReadWriteSeek, TP: TimeProvider, OCC> DirIter<'a, IO, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
impl<'a, IO: ReadWriteSeek, TP: TimeProvider, OCC> DirIter<'a, IO, TP, OCC> {
fn should_skip_entry(&self, raw_entry: &DirEntryData) -> bool {
if raw_entry.is_deleted() {
return true;
Expand Down Expand Up @@ -833,10 +787,7 @@ where
}

// Note: derive cannot be used because of invalid bounds. See: https://github.com/rust-lang/rust/issues/26925
impl<IO: ReadWriteSeek, TP, OCC> Clone for DirIter<'_, IO, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
impl<IO: ReadWriteSeek, TP, OCC> Clone for DirIter<'_, IO, TP, OCC> {
fn clone(&self) -> Self {
Self {
stream: self.stream.clone(),
Expand All @@ -847,10 +798,7 @@ where
}
}

impl<'a, IO: ReadWriteSeek, TP: TimeProvider, OCC> AsyncIterator for DirIter<'a, IO, TP, OCC>
where
IO::Error: From<ReadExactError<IO::Error>> + From<WriteAllError<IO::Error>>,
{
impl<'a, IO: ReadWriteSeek, TP: TimeProvider, OCC> AsyncIterator for DirIter<'a, IO, TP, OCC> {
type Item = Result<DirEntry<'a, IO, TP, OCC>, Error<IO::Error>>;

async fn next(&mut self) -> Option<Self::Item> {
Expand Down
Loading

0 comments on commit 3b5bb06

Please sign in to comment.