diff --git a/src/dev/mod.rs b/src/dev/mod.rs index 815aaf1..48a17c5 100644 --- a/src/dev/mod.rs +++ b/src/dev/mod.rs @@ -325,7 +325,7 @@ impl_device!(&mut [T]); impl_device!(Vec); impl_device!(Box<[T]>); -#[cfg(not(no_std))] +#[cfg(feature = "std")] impl Device for RefCell { #[inline] fn size(&self) -> Size { diff --git a/src/error.rs b/src/error.rs index 4f42592..9fac586 100644 --- a/src/error.rs +++ b/src/error.rs @@ -19,6 +19,10 @@ pub enum Error { /// Path error Path(PathError), + + /// Standard I/O error + #[cfg(feature = "std")] + IO(std::io::Error), } impl Display for Error { @@ -28,6 +32,8 @@ impl Display for Error { Self::Device(device_error) => write!(formatter, "Device Error: {device_error}"), Self::Fs(fs_error) => write!(formatter, "Filesystem Error: {fs_error}"), Self::Path(path_error) => write!(formatter, "Path Error: {path_error}"), + #[cfg(feature = "std")] + Self::IO(io_error) => write!(formatter, "I/O Error: {io_error}"), } } } diff --git a/src/io.rs b/src/io.rs index f33be4f..9e1369a 100644 --- a/src/io.rs +++ b/src/io.rs @@ -20,10 +20,11 @@ pub trait Read { fn read(&mut self, buf: &mut [u8]) -> Result>; } -impl> Read for &mut S { +#[cfg(feature = "std")] +impl Read for S { #[inline] fn read(&mut self, buf: &mut [u8]) -> Result> { - (**self).read(buf) + std::io::Read::read(self, buf).map_err(|err| Error::IO(err)) } } @@ -54,15 +55,16 @@ pub trait Write { fn flush(&mut self) -> Result<(), Error>; } -impl> Write for &mut S { +#[cfg(feature = "std")] +impl Write for S { #[inline] fn write(&mut self, buf: &[u8]) -> Result> { - (**self).write(buf) + std::io::Write::write(self, buf).map_err(|err| Error::IO(err)) } #[inline] fn flush(&mut self) -> Result<(), Error> { - (**self).flush() + std::io::Write::flush(self).map_err(|err| Error::IO(err)) } } @@ -85,6 +87,30 @@ pub enum SeekFrom { Current(i64), } +#[cfg(feature = "std")] +impl From for SeekFrom { + #[inline] + fn from(value: std::io::SeekFrom) -> Self { + match value { + std::io::SeekFrom::Start(value) => Self::Start(value), + std::io::SeekFrom::End(value) => Self::End(value), + std::io::SeekFrom::Current(value) => Self::Current(value), + } + } +} + +#[cfg(feature = "std")] +impl From for std::io::SeekFrom { + #[inline] + fn from(value: SeekFrom) -> Self { + match value { + SeekFrom::Start(value) => Self::Start(value), + SeekFrom::End(value) => Self::End(value), + SeekFrom::Current(value) => Self::Current(value), + } + } +} + /// Provides a cursor which can be moved within a stream of bytes. /// /// See [`std::io::Seek`] for more information: this trait is a `no_std` based variant. @@ -99,9 +125,10 @@ pub trait Seek { fn seek(&mut self, pos: SeekFrom) -> Result>; } -impl> Seek for &mut S { +#[cfg(feature = "std")] +impl Seek for S { #[inline] fn seek(&mut self, pos: SeekFrom) -> Result> { - (**self).seek(pos) + std::io::Seek::seek(self, pos.into()).map_err(|err| Error::IO(err)) } }