Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions embedded-io-adapters/src/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ impl<T: ?Sized> embedded_io::ErrorType for FromStd<T> {
type Error = std::io::Error;
}

#[deny(
clippy::missing_trait_methods,
reason = "Methods should be forwarded to the underlying type"
)]
impl<T: std::io::Read + ?Sized> embedded_io::Read for FromStd<T> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
self.inner.read(buf)
Expand All @@ -55,6 +59,10 @@ impl<T: std::io::Read + ?Sized> embedded_io::Read for FromStd<T> {
}
}

#[deny(
clippy::missing_trait_methods,
reason = "Methods should be forwarded to the underlying type"
)]
impl<T: std::io::BufRead + ?Sized> embedded_io::BufRead for FromStd<T> {
fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
self.inner.fill_buf()
Expand All @@ -65,6 +73,10 @@ impl<T: std::io::BufRead + ?Sized> embedded_io::BufRead for FromStd<T> {
}
}

#[deny(
clippy::missing_trait_methods,
reason = "Methods should be forwarded to the underlying type"
)]
impl<T: std::io::Write + ?Sized> embedded_io::Write for FromStd<T> {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
match self.inner.write(buf) {
Expand All @@ -90,6 +102,10 @@ impl<T: std::io::Write + ?Sized> embedded_io::Write for FromStd<T> {
}
}

#[deny(
clippy::missing_trait_methods,
reason = "Methods should be forwarded to the underlying type"
)]
impl<T: std::io::Seek + ?Sized> embedded_io::Seek for FromStd<T> {
fn seek(&mut self, pos: embedded_io::SeekFrom) -> Result<u64, Self::Error> {
self.inner.seek(pos.into())
Expand Down
66 changes: 66 additions & 0 deletions embedded-io-async/src/impls/blanket.rs
Original file line number Diff line number Diff line change
@@ -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<T: ?Sized + Read> Read for &mut T {
#[inline]
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
T::read(self, buf).await
}

#[inline]
async fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), ReadExactError<Self::Error>> {
T::read_exact(self, buf).await
}
}

impl<T: ?Sized + BufRead> 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<T: ?Sized + Write> Write for &mut T {
#[inline]
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
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<T: ?Sized + Seek> Seek for &mut T {
#[inline]
async fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error> {
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<u64, Self::Error> {
T::stream_position(self).await
}
}
5 changes: 5 additions & 0 deletions embedded-io-async/src/impls/boxx.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
1 change: 1 addition & 0 deletions embedded-io-async/src/impls/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod blanket;
mod slice_mut;
mod slice_ref;

Expand Down
58 changes: 0 additions & 58 deletions embedded-io-async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,61 +167,3 @@ pub trait Seek: ErrorType {
self.seek(SeekFrom::Current(0)).await
}
}

impl<T: ?Sized + Read> Read for &mut T {
#[inline]
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
T::read(self, buf).await
}

#[inline]
async fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), ReadExactError<Self::Error>> {
T::read_exact(self, buf).await
}
}

impl<T: ?Sized + BufRead> 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<T: ?Sized + Write> Write for &mut T {
#[inline]
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
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<T: ?Sized + Seek> Seek for &mut T {
#[inline]
async fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error> {
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<u64, Self::Error> {
T::stream_position(self).await
}
}
92 changes: 92 additions & 0 deletions embedded-io/src/impls/blanket.rs
Original file line number Diff line number Diff line change
@@ -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<T: ?Sized + Read> Read for &mut T {
#[inline]
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
T::read(self, buf)
}

#[inline]
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), ReadExactError<Self::Error>> {
T::read_exact(self, buf)
}
}

impl<T: ?Sized + BufRead> 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<T: ?Sized + Write> Write for &mut T {
#[inline]
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
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<Self::Error>> {
T::write_fmt(self, fmt)
}
}

impl<T: ?Sized + Seek> Seek for &mut T {
#[inline]
fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error> {
T::seek(self, pos)
}

#[inline]
fn rewind(&mut self) -> Result<(), Self::Error> {
T::rewind(self)
}

#[inline]
fn stream_position(&mut self) -> Result<u64, Self::Error> {
T::stream_position(self)
}

#[inline]
fn seek_relative(&mut self, offset: i64) -> Result<(), Self::Error> {
T::seek_relative(self, offset)
}
}

impl<T: ?Sized + ReadReady> ReadReady for &mut T {
#[inline]
fn read_ready(&mut self) -> Result<bool, Self::Error> {
T::read_ready(self)
}
}

impl<T: ?Sized + WriteReady> WriteReady for &mut T {
#[inline]
fn write_ready(&mut self) -> Result<bool, Self::Error> {
T::write_ready(self)
}
}
6 changes: 6 additions & 0 deletions embedded-io/src/impls/boxx.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -21,6 +26,7 @@ impl<T: ?Sized + Read> Read for Box<T> {

#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
impl<T: ?Sized + BufRead> BufRead for Box<T> {
#[inline]
fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
T::fill_buf(self)
}
Expand Down
1 change: 1 addition & 0 deletions embedded-io/src/impls/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod blanket;
mod slice_mut;
mod slice_ref;

Expand Down
77 changes: 0 additions & 77 deletions embedded-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool, Self::Error>;
}

impl<T: ?Sized + Read> Read for &mut T {
#[inline]
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
T::read(self, buf)
}

#[inline]
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), ReadExactError<Self::Error>> {
T::read_exact(self, buf)
}
}

impl<T: ?Sized + BufRead> 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<T: ?Sized + Write> Write for &mut T {
#[inline]
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
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<T: ?Sized + Seek> Seek for &mut T {
#[inline]
fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error> {
T::seek(self, pos)
}

#[inline]
fn rewind(&mut self) -> Result<(), Self::Error> {
T::rewind(self)
}

#[inline]
fn stream_position(&mut self) -> Result<u64, Self::Error> {
T::stream_position(self)
}

#[inline]
fn seek_relative(&mut self, offset: i64) -> Result<(), Self::Error> {
T::seek_relative(self, offset)
}
}

impl<T: ?Sized + ReadReady> ReadReady for &mut T {
#[inline]
fn read_ready(&mut self) -> Result<bool, Self::Error> {
T::read_ready(self)
}
}

impl<T: ?Sized + WriteReady> WriteReady for &mut T {
#[inline]
fn write_ready(&mut self) -> Result<bool, Self::Error> {
T::write_ready(self)
}
}