Skip to content

Commit 0562eee

Browse files
authored
Merge pull request #711 from Conaclos/lint-adapter
io: use clippy to ensure that methods are forwarded in adapters
2 parents fbb5c79 + 2b72166 commit 0562eee

File tree

9 files changed

+187
-135
lines changed

9 files changed

+187
-135
lines changed

embedded-io-adapters/src/std.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ impl<T: ?Sized> embedded_io::ErrorType for FromStd<T> {
3636
type Error = std::io::Error;
3737
}
3838

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

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

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

105+
#[deny(
106+
clippy::missing_trait_methods,
107+
reason = "Methods should be forwarded to the underlying type"
108+
)]
93109
impl<T: std::io::Seek + ?Sized> embedded_io::Seek for FromStd<T> {
94110
fn seek(&mut self, pos: embedded_io::SeekFrom) -> Result<u64, Self::Error> {
95111
self.inner.seek(pos.into())
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#![deny(
2+
clippy::missing_trait_methods,
3+
reason = "Methods should be forwarded to the underlying type"
4+
)]
5+
6+
use embedded_io::{ReadExactError, SeekFrom};
7+
8+
use crate::{BufRead, Read, Seek, Write};
9+
10+
impl<T: ?Sized + Read> Read for &mut T {
11+
#[inline]
12+
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
13+
T::read(self, buf).await
14+
}
15+
16+
#[inline]
17+
async fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), ReadExactError<Self::Error>> {
18+
T::read_exact(self, buf).await
19+
}
20+
}
21+
22+
impl<T: ?Sized + BufRead> BufRead for &mut T {
23+
#[inline]
24+
async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
25+
T::fill_buf(self).await
26+
}
27+
28+
#[inline]
29+
fn consume(&mut self, amt: usize) {
30+
T::consume(self, amt);
31+
}
32+
}
33+
34+
impl<T: ?Sized + Write> Write for &mut T {
35+
#[inline]
36+
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
37+
T::write(self, buf).await
38+
}
39+
40+
#[inline]
41+
async fn flush(&mut self) -> Result<(), Self::Error> {
42+
T::flush(self).await
43+
}
44+
45+
#[inline]
46+
async fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> {
47+
T::write_all(self, buf).await
48+
}
49+
}
50+
51+
impl<T: ?Sized + Seek> Seek for &mut T {
52+
#[inline]
53+
async fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error> {
54+
T::seek(self, pos).await
55+
}
56+
57+
#[inline]
58+
async fn rewind(&mut self) -> Result<(), Self::Error> {
59+
T::rewind(self).await
60+
}
61+
62+
#[inline]
63+
async fn stream_position(&mut self) -> Result<u64, Self::Error> {
64+
T::stream_position(self).await
65+
}
66+
}

embedded-io-async/src/impls/boxx.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#![deny(
2+
clippy::missing_trait_methods,
3+
reason = "Methods should be forwarded to the underlying type"
4+
)]
5+
16
use crate::{BufRead, Read, Seek, SeekFrom, Write};
27
use alloc::boxed::Box;
38

embedded-io-async/src/impls/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod blanket;
12
mod slice_mut;
23
mod slice_ref;
34

embedded-io-async/src/lib.rs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -167,61 +167,3 @@ pub trait Seek: ErrorType {
167167
self.seek(SeekFrom::Current(0)).await
168168
}
169169
}
170-
171-
impl<T: ?Sized + Read> Read for &mut T {
172-
#[inline]
173-
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
174-
T::read(self, buf).await
175-
}
176-
177-
#[inline]
178-
async fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), ReadExactError<Self::Error>> {
179-
T::read_exact(self, buf).await
180-
}
181-
}
182-
183-
impl<T: ?Sized + BufRead> BufRead for &mut T {
184-
#[inline]
185-
async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
186-
T::fill_buf(self).await
187-
}
188-
189-
#[inline]
190-
fn consume(&mut self, amt: usize) {
191-
T::consume(self, amt);
192-
}
193-
}
194-
195-
impl<T: ?Sized + Write> Write for &mut T {
196-
#[inline]
197-
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
198-
T::write(self, buf).await
199-
}
200-
201-
#[inline]
202-
async fn flush(&mut self) -> Result<(), Self::Error> {
203-
T::flush(self).await
204-
}
205-
206-
#[inline]
207-
async fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> {
208-
T::write_all(self, buf).await
209-
}
210-
}
211-
212-
impl<T: ?Sized + Seek> Seek for &mut T {
213-
#[inline]
214-
async fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error> {
215-
T::seek(self, pos).await
216-
}
217-
218-
#[inline]
219-
async fn rewind(&mut self) -> Result<(), Self::Error> {
220-
T::rewind(self).await
221-
}
222-
223-
#[inline]
224-
async fn stream_position(&mut self) -> Result<u64, Self::Error> {
225-
T::stream_position(self).await
226-
}
227-
}

embedded-io/src/impls/blanket.rs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#![deny(
2+
clippy::missing_trait_methods,
3+
reason = "Methods should be forwarded to the underlying type"
4+
)]
5+
6+
use core::fmt;
7+
8+
use crate::{
9+
BufRead, Read, ReadExactError, ReadReady, Seek, SeekFrom, Write, WriteFmtError, WriteReady,
10+
};
11+
12+
impl<T: ?Sized + Read> Read for &mut T {
13+
#[inline]
14+
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
15+
T::read(self, buf)
16+
}
17+
18+
#[inline]
19+
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), ReadExactError<Self::Error>> {
20+
T::read_exact(self, buf)
21+
}
22+
}
23+
24+
impl<T: ?Sized + BufRead> BufRead for &mut T {
25+
#[inline]
26+
fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
27+
T::fill_buf(self)
28+
}
29+
30+
#[inline]
31+
fn consume(&mut self, amt: usize) {
32+
T::consume(self, amt);
33+
}
34+
}
35+
36+
impl<T: ?Sized + Write> Write for &mut T {
37+
#[inline]
38+
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
39+
T::write(self, buf)
40+
}
41+
42+
#[inline]
43+
fn flush(&mut self) -> Result<(), Self::Error> {
44+
T::flush(self)
45+
}
46+
47+
#[inline]
48+
fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> {
49+
T::write_all(self, buf)
50+
}
51+
52+
#[inline]
53+
fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> Result<(), WriteFmtError<Self::Error>> {
54+
T::write_fmt(self, fmt)
55+
}
56+
}
57+
58+
impl<T: ?Sized + Seek> Seek for &mut T {
59+
#[inline]
60+
fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error> {
61+
T::seek(self, pos)
62+
}
63+
64+
#[inline]
65+
fn rewind(&mut self) -> Result<(), Self::Error> {
66+
T::rewind(self)
67+
}
68+
69+
#[inline]
70+
fn stream_position(&mut self) -> Result<u64, Self::Error> {
71+
T::stream_position(self)
72+
}
73+
74+
#[inline]
75+
fn seek_relative(&mut self, offset: i64) -> Result<(), Self::Error> {
76+
T::seek_relative(self, offset)
77+
}
78+
}
79+
80+
impl<T: ?Sized + ReadReady> ReadReady for &mut T {
81+
#[inline]
82+
fn read_ready(&mut self) -> Result<bool, Self::Error> {
83+
T::read_ready(self)
84+
}
85+
}
86+
87+
impl<T: ?Sized + WriteReady> WriteReady for &mut T {
88+
#[inline]
89+
fn write_ready(&mut self) -> Result<bool, Self::Error> {
90+
T::write_ready(self)
91+
}
92+
}

embedded-io/src/impls/boxx.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#![deny(
2+
clippy::missing_trait_methods,
3+
reason = "Methods should be forwarded to the underlying type"
4+
)]
5+
16
use crate::{BufRead, ErrorType, Read, ReadReady, Seek, Write, WriteReady};
27
use alloc::boxed::Box;
38

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

2227
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
2328
impl<T: ?Sized + BufRead> BufRead for Box<T> {
29+
#[inline]
2430
fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
2531
T::fill_buf(self)
2632
}

embedded-io/src/impls/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod blanket;
12
mod slice_mut;
23
mod slice_ref;
34

embedded-io/src/lib.rs

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -566,80 +566,3 @@ pub trait WriteReady: ErrorType {
566566
/// If this returns `true`, it's guaranteed that the next call to [`Write::write`] will not block.
567567
fn write_ready(&mut self) -> Result<bool, Self::Error>;
568568
}
569-
570-
impl<T: ?Sized + Read> Read for &mut T {
571-
#[inline]
572-
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
573-
T::read(self, buf)
574-
}
575-
576-
#[inline]
577-
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), ReadExactError<Self::Error>> {
578-
T::read_exact(self, buf)
579-
}
580-
}
581-
582-
impl<T: ?Sized + BufRead> BufRead for &mut T {
583-
#[inline]
584-
fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
585-
T::fill_buf(self)
586-
}
587-
588-
#[inline]
589-
fn consume(&mut self, amt: usize) {
590-
T::consume(self, amt);
591-
}
592-
}
593-
594-
impl<T: ?Sized + Write> Write for &mut T {
595-
#[inline]
596-
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
597-
T::write(self, buf)
598-
}
599-
600-
#[inline]
601-
fn flush(&mut self) -> Result<(), Self::Error> {
602-
T::flush(self)
603-
}
604-
605-
#[inline]
606-
fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> {
607-
T::write_all(self, buf)
608-
}
609-
}
610-
611-
impl<T: ?Sized + Seek> Seek for &mut T {
612-
#[inline]
613-
fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error> {
614-
T::seek(self, pos)
615-
}
616-
617-
#[inline]
618-
fn rewind(&mut self) -> Result<(), Self::Error> {
619-
T::rewind(self)
620-
}
621-
622-
#[inline]
623-
fn stream_position(&mut self) -> Result<u64, Self::Error> {
624-
T::stream_position(self)
625-
}
626-
627-
#[inline]
628-
fn seek_relative(&mut self, offset: i64) -> Result<(), Self::Error> {
629-
T::seek_relative(self, offset)
630-
}
631-
}
632-
633-
impl<T: ?Sized + ReadReady> ReadReady for &mut T {
634-
#[inline]
635-
fn read_ready(&mut self) -> Result<bool, Self::Error> {
636-
T::read_ready(self)
637-
}
638-
}
639-
640-
impl<T: ?Sized + WriteReady> WriteReady for &mut T {
641-
#[inline]
642-
fn write_ready(&mut self) -> Result<bool, Self::Error> {
643-
T::write_ready(self)
644-
}
645-
}

0 commit comments

Comments
 (0)