diff --git a/embedded-io-adapters/src/std.rs b/embedded-io-adapters/src/std.rs index 776bc875..83f6e65e 100644 --- a/embedded-io-adapters/src/std.rs +++ b/embedded-io-adapters/src/std.rs @@ -36,6 +36,10 @@ impl embedded_io::ErrorType for FromStd { type Error = std::io::Error; } +#[deny( + clippy::missing_trait_methods, + reason = "Methods should be forwarded to the underlying type" +)] impl embedded_io::Read for FromStd { fn read(&mut self, buf: &mut [u8]) -> Result { self.inner.read(buf) @@ -55,6 +59,10 @@ impl embedded_io::Read for FromStd { } } +#[deny( + clippy::missing_trait_methods, + reason = "Methods should be forwarded to the underlying type" +)] impl embedded_io::BufRead for FromStd { fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { self.inner.fill_buf() @@ -65,6 +73,10 @@ impl embedded_io::BufRead for FromStd { } } +#[deny( + clippy::missing_trait_methods, + reason = "Methods should be forwarded to the underlying type" +)] impl embedded_io::Write for FromStd { fn write(&mut self, buf: &[u8]) -> Result { match self.inner.write(buf) { @@ -90,6 +102,10 @@ impl embedded_io::Write for FromStd { } } +#[deny( + clippy::missing_trait_methods, + reason = "Methods should be forwarded to the underlying type" +)] impl embedded_io::Seek for FromStd { fn seek(&mut self, pos: embedded_io::SeekFrom) -> Result { self.inner.seek(pos.into()) diff --git a/embedded-io-async/src/impls/blanket.rs b/embedded-io-async/src/impls/blanket.rs new file mode 100644 index 00000000..67e69736 --- /dev/null +++ b/embedded-io-async/src/impls/blanket.rs @@ -0,0 +1,66 @@ +#![deny( + clippy::missing_trait_methods, + reason = "Methods should be forwarded to the underlying type" +)] + +use embedded_io::{ReadExactError, SeekFrom}; + +use crate::{BufRead, Read, Seek, Write}; + +impl Read for &mut T { + #[inline] + async fn read(&mut self, buf: &mut [u8]) -> Result { + T::read(self, buf).await + } + + #[inline] + async fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), ReadExactError> { + T::read_exact(self, buf).await + } +} + +impl BufRead for &mut T { + #[inline] + async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { + T::fill_buf(self).await + } + + #[inline] + fn consume(&mut self, amt: usize) { + T::consume(self, amt); + } +} + +impl Write for &mut T { + #[inline] + async fn write(&mut self, buf: &[u8]) -> Result { + T::write(self, buf).await + } + + #[inline] + async fn flush(&mut self) -> Result<(), Self::Error> { + T::flush(self).await + } + + #[inline] + async fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> { + T::write_all(self, buf).await + } +} + +impl Seek for &mut T { + #[inline] + async fn seek(&mut self, pos: SeekFrom) -> Result { + T::seek(self, pos).await + } + + #[inline] + async fn rewind(&mut self) -> Result<(), Self::Error> { + T::rewind(self).await + } + + #[inline] + async fn stream_position(&mut self) -> Result { + T::stream_position(self).await + } +} diff --git a/embedded-io-async/src/impls/boxx.rs b/embedded-io-async/src/impls/boxx.rs index b3c1bab5..c8ee9e84 100644 --- a/embedded-io-async/src/impls/boxx.rs +++ b/embedded-io-async/src/impls/boxx.rs @@ -1,3 +1,8 @@ +#![deny( + clippy::missing_trait_methods, + reason = "Methods should be forwarded to the underlying type" +)] + use crate::{BufRead, Read, Seek, SeekFrom, Write}; use alloc::boxed::Box; diff --git a/embedded-io-async/src/impls/mod.rs b/embedded-io-async/src/impls/mod.rs index 83c0f33a..69565952 100644 --- a/embedded-io-async/src/impls/mod.rs +++ b/embedded-io-async/src/impls/mod.rs @@ -1,3 +1,4 @@ +mod blanket; mod slice_mut; mod slice_ref; diff --git a/embedded-io-async/src/lib.rs b/embedded-io-async/src/lib.rs index a421e54c..b90935f2 100644 --- a/embedded-io-async/src/lib.rs +++ b/embedded-io-async/src/lib.rs @@ -167,61 +167,3 @@ pub trait Seek: ErrorType { self.seek(SeekFrom::Current(0)).await } } - -impl Read for &mut T { - #[inline] - async fn read(&mut self, buf: &mut [u8]) -> Result { - T::read(self, buf).await - } - - #[inline] - async fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), ReadExactError> { - T::read_exact(self, buf).await - } -} - -impl BufRead for &mut T { - #[inline] - async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { - T::fill_buf(self).await - } - - #[inline] - fn consume(&mut self, amt: usize) { - T::consume(self, amt); - } -} - -impl Write for &mut T { - #[inline] - async fn write(&mut self, buf: &[u8]) -> Result { - T::write(self, buf).await - } - - #[inline] - async fn flush(&mut self) -> Result<(), Self::Error> { - T::flush(self).await - } - - #[inline] - async fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> { - T::write_all(self, buf).await - } -} - -impl Seek for &mut T { - #[inline] - async fn seek(&mut self, pos: SeekFrom) -> Result { - T::seek(self, pos).await - } - - #[inline] - async fn rewind(&mut self) -> Result<(), Self::Error> { - T::rewind(self).await - } - - #[inline] - async fn stream_position(&mut self) -> Result { - T::stream_position(self).await - } -} diff --git a/embedded-io/src/impls/blanket.rs b/embedded-io/src/impls/blanket.rs new file mode 100644 index 00000000..a62f654e --- /dev/null +++ b/embedded-io/src/impls/blanket.rs @@ -0,0 +1,92 @@ +#![deny( + clippy::missing_trait_methods, + reason = "Methods should be forwarded to the underlying type" +)] + +use core::fmt; + +use crate::{ + BufRead, Read, ReadExactError, ReadReady, Seek, SeekFrom, Write, WriteFmtError, WriteReady, +}; + +impl Read for &mut T { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> Result { + T::read(self, buf) + } + + #[inline] + fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), ReadExactError> { + T::read_exact(self, buf) + } +} + +impl BufRead for &mut T { + #[inline] + fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { + T::fill_buf(self) + } + + #[inline] + fn consume(&mut self, amt: usize) { + T::consume(self, amt); + } +} + +impl Write for &mut T { + #[inline] + fn write(&mut self, buf: &[u8]) -> Result { + T::write(self, buf) + } + + #[inline] + fn flush(&mut self) -> Result<(), Self::Error> { + T::flush(self) + } + + #[inline] + fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> { + T::write_all(self, buf) + } + + #[inline] + fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> Result<(), WriteFmtError> { + T::write_fmt(self, fmt) + } +} + +impl Seek for &mut T { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> Result { + T::seek(self, pos) + } + + #[inline] + fn rewind(&mut self) -> Result<(), Self::Error> { + T::rewind(self) + } + + #[inline] + fn stream_position(&mut self) -> Result { + T::stream_position(self) + } + + #[inline] + fn seek_relative(&mut self, offset: i64) -> Result<(), Self::Error> { + T::seek_relative(self, offset) + } +} + +impl ReadReady for &mut T { + #[inline] + fn read_ready(&mut self) -> Result { + T::read_ready(self) + } +} + +impl WriteReady for &mut T { + #[inline] + fn write_ready(&mut self) -> Result { + T::write_ready(self) + } +} diff --git a/embedded-io/src/impls/boxx.rs b/embedded-io/src/impls/boxx.rs index c7bb01a5..02282eee 100644 --- a/embedded-io/src/impls/boxx.rs +++ b/embedded-io/src/impls/boxx.rs @@ -1,3 +1,8 @@ +#![deny( + clippy::missing_trait_methods, + reason = "Methods should be forwarded to the underlying type" +)] + use crate::{BufRead, ErrorType, Read, ReadReady, Seek, Write, WriteReady}; use alloc::boxed::Box; @@ -21,6 +26,7 @@ impl Read for Box { #[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] impl BufRead for Box { + #[inline] fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { T::fill_buf(self) } diff --git a/embedded-io/src/impls/mod.rs b/embedded-io/src/impls/mod.rs index 83c0f33a..69565952 100644 --- a/embedded-io/src/impls/mod.rs +++ b/embedded-io/src/impls/mod.rs @@ -1,3 +1,4 @@ +mod blanket; mod slice_mut; mod slice_ref; diff --git a/embedded-io/src/lib.rs b/embedded-io/src/lib.rs index 0918cdb5..cdd89534 100644 --- a/embedded-io/src/lib.rs +++ b/embedded-io/src/lib.rs @@ -552,80 +552,3 @@ pub trait WriteReady: ErrorType { /// If this returns `true`, it's guaranteed that the next call to [`Write::write`] will not block. fn write_ready(&mut self) -> Result; } - -impl Read for &mut T { - #[inline] - fn read(&mut self, buf: &mut [u8]) -> Result { - T::read(self, buf) - } - - #[inline] - fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), ReadExactError> { - T::read_exact(self, buf) - } -} - -impl BufRead for &mut T { - #[inline] - fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { - T::fill_buf(self) - } - - #[inline] - fn consume(&mut self, amt: usize) { - T::consume(self, amt); - } -} - -impl Write for &mut T { - #[inline] - fn write(&mut self, buf: &[u8]) -> Result { - T::write(self, buf) - } - - #[inline] - fn flush(&mut self) -> Result<(), Self::Error> { - T::flush(self) - } - - #[inline] - fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> { - T::write_all(self, buf) - } -} - -impl Seek for &mut T { - #[inline] - fn seek(&mut self, pos: SeekFrom) -> Result { - T::seek(self, pos) - } - - #[inline] - fn rewind(&mut self) -> Result<(), Self::Error> { - T::rewind(self) - } - - #[inline] - fn stream_position(&mut self) -> Result { - T::stream_position(self) - } - - #[inline] - fn seek_relative(&mut self, offset: i64) -> Result<(), Self::Error> { - T::seek_relative(self, offset) - } -} - -impl ReadReady for &mut T { - #[inline] - fn read_ready(&mut self) -> Result { - T::read_ready(self) - } -} - -impl WriteReady for &mut T { - #[inline] - fn write_ready(&mut self) -> Result { - T::write_ready(self) - } -}