Skip to content

Commit dfc94f6

Browse files
committed
remove void dep, use core::convert::Infallible instead
there's no need for the `void` dependency anymore. accordingly it can be removed. this will also help with implementing `embedded-hal` v1 traits as some of them rely on (or at least have better support for) `core::convert::Infallible`. this is a breaking change for consumers as they have to e.g. replace `void_unwrap()` calls with `unwrap()`. the prelude is now no longer needed in most cases (potentally the whole `mod prelude` could be removed in the future as it now adds little benefit?). note that this PR will conflict with #481; when one gets merged i'll have to rebase the other on top of it (though it will be a fairly trivial rebase). this is due to the fact that both modify the same lines in a few places. merging this one here first might be easier as the other one is smaller.
1 parent f6b79dc commit dfc94f6

48 files changed

Lines changed: 179 additions & 235 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

arduino-hal/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ ufmt = "0.2.0"
3434
version = "0.2.3"
3535
package = "embedded-hal"
3636

37-
[dependencies.void]
38-
version = "1.0.2"
39-
default-features = false
40-
4137
[dependencies.avr-hal-generic]
4238
path = "../avr-hal-generic/"
4339

avr-hal-generic/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,5 @@ version = "0.2.3"
1818
package = "embedded-hal"
1919
features = ["unproven"]
2020

21-
[dependencies.void]
22-
version = "1.0.2"
23-
default-features = false
24-
2521
[build-dependencies]
2622
rustversion = "1.0"

avr-hal-generic/src/adc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<H, ADC: AdcOps<H>> AdcChannel<H, ADC> for Channel<H, ADC> {
132132
/// let voltage = adc.read_blocking(&a0);
133133
///
134134
/// // alternatively, a non-blocking interface exists
135-
/// let voltage = nb::block!(adc.read_nonblocking(&a0)).void_unwrap();
135+
/// let voltage = nb::block!(adc.read_nonblocking(&a0)).unwrap();
136136
/// ```
137137
pub struct Adc<H, ADC: AdcOps<H>, CLOCK> {
138138
p: ADC,
@@ -177,7 +177,7 @@ where
177177
pub fn read_nonblocking<PIN: AdcChannel<H, ADC>>(
178178
&mut self,
179179
pin: &PIN,
180-
) -> nb::Result<u16, void::Void> {
180+
) -> nb::Result<u16, core::convert::Infallible> {
181181
match (&self.reading_channel, self.p.raw_is_converting()) {
182182
// Measurement on current pin is ongoing
183183
(Some(channel), true) if *channel == pin.channel() => Err(nb::Error::WouldBlock),

avr-hal-generic/src/eeprom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ where
4040
pub fn new(p: EEPROM) -> Self {
4141
Self {
4242
p,
43-
_h: ::core::marker::PhantomData,
43+
_h: marker::PhantomData,
4444
}
4545
}
4646
#[inline]

avr-hal-generic/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ pub extern crate nb;
1212
pub extern crate paste;
1313
#[doc(hidden)]
1414
pub extern crate ufmt;
15-
#[doc(hidden)]
16-
pub extern crate void;
1715

1816
pub mod adc;
1917
pub mod clock;
@@ -30,8 +28,6 @@ pub mod wdt;
3028
pub mod prelude {
3129
pub use hal::prelude::*;
3230
pub use ufmt::uWrite as _ufmt_uWrite;
33-
pub use void::ResultVoidErrExt as _void_ResultVoidErrExt;
34-
pub use void::ResultVoidExt as _void_ResultVoidExt;
3531
}
3632

3733
// For making certain traits unimplementable from outside this crate.

avr-hal-generic/src/spi.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ where
193193
}
194194

195195
/// Reconfigure the SPI peripheral after initializing
196-
pub fn reconfigure(&mut self, settings: Settings) -> nb::Result<(), crate::void::Void> {
196+
pub fn reconfigure(&mut self, settings: Settings) -> nb::Result<(), core::convert::Infallible> {
197197
// wait for any in-flight writes to complete
198198
self.flush()?;
199199
self.p.raw_setup(&settings);
@@ -217,7 +217,7 @@ where
217217
(self.p, self.sclk, self.mosi, self.miso, cs.0)
218218
}
219219

220-
fn flush(&mut self) -> nb::Result<(), void::Void> {
220+
fn flush(&mut self) -> nb::Result<(), core::convert::Infallible> {
221221
if self.write_in_progress {
222222
if self.p.raw_check_iflag() {
223223
self.write_in_progress = false;
@@ -250,7 +250,7 @@ where
250250
MISOPIN: port::PinOps,
251251
CSPIN: port::PinOps,
252252
{
253-
type Error = void::Void;
253+
type Error = core::convert::Infallible;
254254

255255
/// Sets up the device for transmission and sends the data
256256
fn send(&mut self, byte: u8) -> nb::Result<(), Self::Error> {

avr-hal-generic/src/usart.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
use core::cmp::Ordering;
66
use core::marker;
7-
use void::ResultVoidExt;
87

98
use crate::port;
109

@@ -62,7 +61,7 @@ impl<CLOCK: crate::clock::Clock> Baudrate<CLOCK> {
6261
Baudrate {
6362
ubrr: ubrr as u16,
6463
u2x,
65-
_clock: ::core::marker::PhantomData,
64+
_clock: marker::PhantomData,
6665
}
6766
}
6867

@@ -73,7 +72,7 @@ impl<CLOCK: crate::clock::Clock> Baudrate<CLOCK> {
7372
Baudrate {
7473
ubrr,
7574
u2x,
76-
_clock: ::core::marker::PhantomData,
75+
_clock: marker::PhantomData,
7776
}
7877
}
7978

@@ -184,21 +183,21 @@ pub trait UsartOps<H, RX, TX> {
184183
/// was flushed yet.
185184
///
186185
/// **Warning**: This is a low-level method and should not be called directly from user code.
187-
fn raw_flush(&mut self) -> nb::Result<(), void::Void>;
186+
fn raw_flush(&mut self) -> nb::Result<(), core::convert::Infallible>;
188187
/// Write a byte to the TX buffer.
189188
///
190189
/// This operation must be non-blocking and return [`nb::Error::WouldBlock`] until the byte is
191190
/// enqueued. The operation should not wait for the byte to have actually been sent.
192191
///
193192
/// **Warning**: This is a low-level method and should not be called directly from user code.
194-
fn raw_write(&mut self, byte: u8) -> nb::Result<(), void::Void>;
193+
fn raw_write(&mut self, byte: u8) -> nb::Result<(), core::convert::Infallible>;
195194
/// Read a byte from the RX buffer.
196195
///
197196
/// This operation must be non-blocking and return [`nb::Error::WouldBlock`] if no incoming
198197
/// byte is available.
199198
///
200199
/// **Warning**: This is a low-level method and should not be called directly from user code.
201-
fn raw_read(&mut self) -> nb::Result<u8, void::Void>;
200+
fn raw_read(&mut self) -> nb::Result<u8, core::convert::Infallible>;
202201

203202
/// Enable/Disable a certain interrupt.
204203
///
@@ -220,11 +219,11 @@ pub trait UsartOps<H, RX, TX> {
220219
/// 57600.into_baudrate(),
221220
/// );
222221
///
223-
/// ufmt::uwriteln!(&mut serial, "Hello from Arduino!\r").void_unwrap();
222+
/// ufmt::uwriteln!(&mut serial, "Hello from Arduino!\r").unwrap();
224223
///
225224
/// loop {
226-
/// let b = nb::block!(serial.read()).void_unwrap();
227-
/// ufmt::uwriteln!(&mut serial, "Got {}!\r", b).void_unwrap();
225+
/// let b = nb::block!(serial.read()).unwrap();
226+
/// ufmt::uwriteln!(&mut serial, "Got {}!\r", b).unwrap();
228227
/// }
229228
/// ```
230229
pub struct Usart<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> {
@@ -279,22 +278,22 @@ impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> Usart<H, USART, RX, TX, CLOCK
279278

280279
/// Block until all remaining data has been transmitted.
281280
pub fn flush(&mut self) {
282-
nb::block!(self.p.raw_flush()).void_unwrap()
281+
nb::block!(self.p.raw_flush()).unwrap()
283282
}
284283

285284
/// Transmit a byte.
286285
///
287286
/// This method will block until the byte has been enqueued for transmission but **not** until
288287
/// it was entirely sent.
289288
pub fn write_byte(&mut self, byte: u8) {
290-
nb::block!(self.p.raw_write(byte)).void_unwrap()
289+
nb::block!(self.p.raw_write(byte)).unwrap()
291290
}
292291

293292
/// Receive a byte.
294293
///
295294
/// This method will block until a byte could be received.
296295
pub fn read_byte(&mut self) -> u8 {
297-
nb::block!(self.p.raw_read()).void_unwrap()
296+
nb::block!(self.p.raw_read()).unwrap()
298297
}
299298

300299
/// Enable the interrupt for [`Event`].
@@ -336,7 +335,7 @@ impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> Usart<H, USART, RX, TX, CLOCK
336335
}
337336

338337
impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> ufmt::uWrite for Usart<H, USART, RX, TX, CLOCK> {
339-
type Error = void::Void;
338+
type Error = core::convert::Infallible;
340339

341340
fn write_str(&mut self, s: &str) -> Result<(), Self::Error> {
342341
for b in s.as_bytes().iter() {
@@ -349,7 +348,7 @@ impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> ufmt::uWrite for Usart<H, USA
349348
impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> hal::serial::Write<u8>
350349
for Usart<H, USART, RX, TX, CLOCK>
351350
{
352-
type Error = void::Void;
351+
type Error = core::convert::Infallible;
353352

354353
fn write(&mut self, byte: u8) -> nb::Result<(), Self::Error> {
355354
self.p.raw_write(byte)
@@ -363,7 +362,7 @@ impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> hal::serial::Write<u8>
363362
impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> hal::serial::Read<u8>
364363
for Usart<H, USART, RX, TX, CLOCK>
365364
{
366-
type Error = void::Void;
365+
type Error = core::convert::Infallible;
367366

368367
fn read(&mut self) -> nb::Result<u8, Self::Error> {
369368
self.p.raw_read()
@@ -434,11 +433,11 @@ impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> UsartReader<H, USART, RX, TX,
434433
impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> ufmt::uWrite
435434
for UsartWriter<H, USART, RX, TX, CLOCK>
436435
{
437-
type Error = void::Void;
436+
type Error = core::convert::Infallible;
438437

439438
fn write_str(&mut self, s: &str) -> Result<(), Self::Error> {
440439
for b in s.as_bytes().iter() {
441-
nb::block!(self.p.raw_write(*b)).void_unwrap()
440+
nb::block!(self.p.raw_write(*b)).unwrap()
442441
}
443442
Ok(())
444443
}
@@ -447,7 +446,7 @@ impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> ufmt::uWrite
447446
impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> hal::serial::Write<u8>
448447
for UsartWriter<H, USART, RX, TX, CLOCK>
449448
{
450-
type Error = void::Void;
449+
type Error = core::convert::Infallible;
451450

452451
fn write(&mut self, byte: u8) -> nb::Result<(), Self::Error> {
453452
self.p.raw_write(byte)
@@ -461,7 +460,7 @@ impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> hal::serial::Write<u8>
461460
impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> hal::serial::Read<u8>
462461
for UsartReader<H, USART, RX, TX, CLOCK>
463462
{
464-
type Error = void::Void;
463+
type Error = core::convert::Infallible;
465464

466465
fn read(&mut self) -> nb::Result<u8, Self::Error> {
467466
self.p.raw_read()
@@ -509,23 +508,23 @@ macro_rules! impl_usart_traditional {
509508
self.[<ucsr $n b>].reset();
510509
}
511510

512-
fn raw_flush(&mut self) -> $crate::nb::Result<(), $crate::void::Void> {
511+
fn raw_flush(&mut self) -> $crate::nb::Result<(), core::convert::Infallible> {
513512
if self.[<ucsr $n a>].read().[<udre $n>]().bit_is_clear() {
514513
Err($crate::nb::Error::WouldBlock)
515514
} else {
516515
Ok(())
517516
}
518517
}
519518

520-
fn raw_write(&mut self, byte: u8) -> $crate::nb::Result<(), $crate::void::Void> {
519+
fn raw_write(&mut self, byte: u8) -> $crate::nb::Result<(), core::convert::Infallible> {
521520
// Call flush to make sure the data-register is empty
522521
self.raw_flush()?;
523522

524523
self.[<udr $n>].write(|w| unsafe { w.bits(byte) });
525524
Ok(())
526525
}
527526

528-
fn raw_read(&mut self) -> $crate::nb::Result<u8, $crate::void::Void> {
527+
fn raw_read(&mut self) -> $crate::nb::Result<u8, core::convert::Infallible> {
529528
if self.[<ucsr $n a>].read().[<rxc $n>]().bit_is_clear() {
530529
return Err($crate::nb::Error::WouldBlock);
531530
}

examples/arduino-diecimila/src/bin/diecimila-adc.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![no_std]
22
#![no_main]
33

4-
use arduino_hal::prelude::*;
54
use panic_halt as _;
65

76
use arduino_hal::adc;
@@ -18,8 +17,8 @@ fn main() -> ! {
1817
adc.read_blocking(&adc::channel::Vbg),
1918
adc.read_blocking(&adc::channel::Gnd),
2019
);
21-
ufmt::uwriteln!(&mut serial, "Vbandgap: {}", vbg).void_unwrap();
22-
ufmt::uwriteln!(&mut serial, "Ground: {}", gnd).void_unwrap();
20+
ufmt::uwriteln!(&mut serial, "Vbandgap: {}", vbg).unwrap();
21+
ufmt::uwriteln!(&mut serial, "Ground: {}", gnd).unwrap();
2322

2423
// To store multiple channels in an array, we use the `into_channel()` method.
2524
let channels: [adc::Channel; 6] = [
@@ -34,10 +33,10 @@ fn main() -> ! {
3433
loop {
3534
for (i, ch) in channels.iter().enumerate() {
3635
let v = adc.read_blocking(ch);
37-
ufmt::uwrite!(&mut serial, "A{}: {} ", i, v).void_unwrap();
36+
ufmt::uwrite!(&mut serial, "A{}: {} ", i, v).unwrap();
3837
}
3938

40-
ufmt::uwriteln!(&mut serial, "").void_unwrap();
39+
ufmt::uwriteln!(&mut serial, "").unwrap();
4140
arduino_hal::delay_ms(1000);
4241
}
4342
}

examples/arduino-diecimila/src/bin/diecimila-i2cdetect.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![no_std]
22
#![no_main]
33

4-
use arduino_hal::prelude::*;
54
use panic_halt as _;
65

76
#[arduino_hal::entry]
@@ -17,12 +16,12 @@ fn main() -> ! {
1716
50000,
1817
);
1918

20-
ufmt::uwriteln!(&mut serial, "Write direction test:\r").void_unwrap();
19+
ufmt::uwriteln!(&mut serial, "Write direction test:\r").unwrap();
2120
i2c.i2cdetect(&mut serial, arduino_hal::i2c::Direction::Write)
22-
.void_unwrap();
23-
ufmt::uwriteln!(&mut serial, "\r\nRead direction test:\r").void_unwrap();
21+
.unwrap();
22+
ufmt::uwriteln!(&mut serial, "\r\nRead direction test:\r").unwrap();
2423
i2c.i2cdetect(&mut serial, arduino_hal::i2c::Direction::Read)
25-
.void_unwrap();
24+
.unwrap();
2625

2726
loop {}
2827
}

examples/arduino-diecimila/src/bin/diecimila-spi-feedback.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#![no_std]
1616
#![no_main]
1717

18-
use arduino_hal::prelude::*;
1918
use arduino_hal::spi;
2019
use embedded_hal_v0::spi::FullDuplex;
2120
use panic_halt as _;
@@ -40,11 +39,11 @@ fn main() -> ! {
4039

4140
loop {
4241
// Send a byte
43-
nb::block!(spi.send(0b00001111)).void_unwrap();
42+
nb::block!(spi.send(0b00001111)).unwrap();
4443
// Because MISO is connected to MOSI, the read data should be the same
45-
let data = nb::block!(spi.read()).void_unwrap();
44+
let data = nb::block!(spi.read()).unwrap();
4645

47-
ufmt::uwriteln!(&mut serial, "data: {}\r", data).void_unwrap();
46+
ufmt::uwriteln!(&mut serial, "data: {}\r", data).unwrap();
4847
arduino_hal::delay_ms(1000);
4948
}
5049
}

0 commit comments

Comments
 (0)