Skip to content

Commit 5e469f7

Browse files
committed
Use impl Iterator in arguments
This is functionally almost identical, but it is a bit easier to read. For more details, see: <https://doc.rust-lang.org/nightly/edition-guide/rust-2018/trait-system/impl-trait-for-returning-complex-types-with-ease.html#argument-position>
1 parent 8e9037a commit 5e469f7

4 files changed

Lines changed: 49 additions & 46 deletions

File tree

i2c/src/lib.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ where
3131
self.i2c
3232
}
3333

34-
fn send_iter<I>(&mut self, first_byte: u8, data: I) -> Result<(), DisplayError>
35-
where
36-
I: Iterator<Item = u8>,
37-
{
34+
fn send_iter(
35+
&mut self,
36+
first_byte: u8,
37+
data: impl Iterator<Item = u8>,
38+
) -> Result<(), DisplayError> {
3839
let mut writebuf = [0; 17];
3940
let mut i = 1;
4041
let len = writebuf.len();
@@ -71,18 +72,18 @@ where
7172
type Word = u8;
7273

7374
#[inline]
74-
fn send_command_iter<I>(&mut self, iter: I) -> Result<(), DisplayError>
75-
where
76-
I: Iterator<Item = Self::Word>,
77-
{
75+
fn send_command_iter(
76+
&mut self,
77+
iter: impl Iterator<Item = Self::Word>,
78+
) -> Result<(), DisplayError> {
7879
self.send_iter(0, iter)
7980
}
8081

8182
#[inline]
82-
fn send_data_iter<I>(&mut self, iter: I) -> Result<(), DisplayError>
83-
where
84-
I: Iterator<Item = Self::Word>,
85-
{
83+
fn send_data_iter(
84+
&mut self,
85+
iter: impl Iterator<Item = Self::Word>,
86+
) -> Result<(), DisplayError> {
8687
self.send_iter(self.data_byte, iter)
8788
}
8889
}

parallel-gpio/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,19 @@ where
195195
{
196196
type Word = u8;
197197

198-
fn send_command_iter<I>(&mut self, iter: I) -> Result<(), DisplayError>
199-
where
200-
I: Iterator<Item = Self::Word>,
201-
{
198+
fn send_command_iter(
199+
&mut self,
200+
iter: impl Iterator<Item = Self::Word>,
201+
) -> Result<(), DisplayError> {
202202
self.dc.set_low().map_err(|_| DisplayError::DCError)?;
203203

204204
self.send_iter(iter)
205205
}
206206

207-
fn send_data_iter<I>(&mut self, iter: I) -> Result<(), DisplayError>
208-
where
209-
I: Iterator<Item = Self::Word>,
210-
{
207+
fn send_data_iter(
208+
&mut self,
209+
iter: impl Iterator<Item = Self::Word>,
210+
) -> Result<(), DisplayError> {
211211
self.dc.set_high().map_err(|_| DisplayError::DCError)?;
212212

213213
self.send_iter(iter)

spi/src/lib.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use hal::digital::v2::OutputPin;
77

88
use display_interface::{DisplayError, WriteOnlyDataCommand};
99

10-
fn send_iter<SPI: hal::blocking::spi::Write<u8>, I: Iterator<Item = u8>>(
11-
spi: &mut SPI,
12-
iter: I,
10+
fn send_iter(
11+
spi: &mut impl hal::blocking::spi::Write<u8>,
12+
iter: impl Iterator<Item = u8>,
1313
) -> Result<(), DisplayError> {
1414
let mut buf = [0; 32];
1515
let mut i = 0;
@@ -68,10 +68,10 @@ where
6868
type Word = u8;
6969

7070
#[inline]
71-
fn send_command_iter<I>(&mut self, iter: I) -> Result<(), DisplayError>
72-
where
73-
I: Iterator<Item = Self::Word>,
74-
{
71+
fn send_command_iter(
72+
&mut self,
73+
iter: impl Iterator<Item = Self::Word>,
74+
) -> Result<(), DisplayError> {
7575
// Assert chip select pin
7676
self.cs.set_low().map_err(|_| DisplayError::CSError)?;
7777

@@ -88,10 +88,10 @@ where
8888
}
8989

9090
#[inline]
91-
fn send_data_iter<I>(&mut self, iter: I) -> Result<(), DisplayError>
92-
where
93-
I: Iterator<Item = Self::Word>,
94-
{
91+
fn send_data_iter(
92+
&mut self,
93+
iter: impl Iterator<Item = Self::Word>,
94+
) -> Result<(), DisplayError> {
9595
// Assert chip select pin
9696
self.cs.set_low().map_err(|_| DisplayError::CSError)?;
9797

@@ -181,10 +181,10 @@ where
181181
type Word = u8;
182182

183183
#[inline]
184-
fn send_command_iter<I>(&mut self, iter: I) -> Result<(), DisplayError>
185-
where
186-
I: Iterator<Item = Self::Word>,
187-
{
184+
fn send_command_iter(
185+
&mut self,
186+
iter: impl Iterator<Item = Self::Word>,
187+
) -> Result<(), DisplayError> {
188188
// 1 = data, 0 = command
189189
self.dc.set_low().map_err(|_| DisplayError::DCError)?;
190190

@@ -193,10 +193,10 @@ where
193193
}
194194

195195
#[inline]
196-
fn send_data_iter<I>(&mut self, iter: I) -> Result<(), DisplayError>
197-
where
198-
I: Iterator<Item = Self::Word>,
199-
{
196+
fn send_data_iter(
197+
&mut self,
198+
iter: impl Iterator<Item = Self::Word>,
199+
) -> Result<(), DisplayError> {
200200
// 1 = data, 0 = command
201201
self.dc.set_high().map_err(|_| DisplayError::DCError)?;
202202

src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ pub enum DisplayError {
3232
pub trait WriteOnlyDataCommand {
3333
type Word: Copy;
3434

35-
fn send_command_iter<I>(&mut self, iter: I) -> Result<(), DisplayError>
36-
where
37-
I: Iterator<Item = Self::Word>;
38-
39-
fn send_data_iter<I>(&mut self, iter: I) -> Result<(), DisplayError>
40-
where
41-
I: Iterator<Item = Self::Word>;
35+
fn send_command_iter(
36+
&mut self,
37+
iter: impl Iterator<Item = Self::Word>,
38+
) -> Result<(), DisplayError>;
39+
40+
fn send_data_iter(
41+
&mut self,
42+
iter: impl Iterator<Item = Self::Word>,
43+
) -> Result<(), DisplayError>;
4244

4345
#[inline]
4446
fn send_command_slice(&mut self, slice: &[Self::Word]) -> Result<(), DisplayError> {

0 commit comments

Comments
 (0)