Skip to content

Commit a399080

Browse files
bors[bot]Disasm
andauthored
Merge #150
150: Fix error types r=therealprof a=Disasm `core::convert::Infallible` was stabilized in 1.34.0. This PR replaces `Void` and `()` error types with `Infallible`. Note that this is a breaking change. Co-authored-by: Vadim Kaushan <[email protected]>
2 parents 7dd907c + c579281 commit a399080

File tree

5 files changed

+42
-53
lines changed

5 files changed

+42
-53
lines changed

Cargo.toml

-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ readme = "README.md"
1313
repository = "https://github.com/japaric/embedded-hal"
1414
version = "0.2.3"
1515

16-
[dependencies.void]
17-
default-features = false
18-
version = "1.0.2"
19-
2016
[dependencies.nb]
2117
version = "0.1.1"
2218

src/digital/v2.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,15 @@ pub trait ToggleableOutputPin {
5959
/// ```
6060
/// use embedded_hal::digital::v2::{OutputPin, StatefulOutputPin, ToggleableOutputPin};
6161
/// use embedded_hal::digital::v2::toggleable;
62+
/// use std::convert::Infallible;
6263
///
6364
/// /// A virtual output pin that exists purely in software
6465
/// struct MyPin {
6566
/// state: bool
6667
/// }
6768
///
6869
/// impl OutputPin for MyPin {
69-
/// type Error = void::Void;
70+
/// type Error = Infallible;
7071
///
7172
/// fn set_low(&mut self) -> Result<(), Self::Error> {
7273
/// self.state = false;

src/digital/v2_compat.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
//! ```
3333
//!
3434
35+
use core::convert::Infallible;
36+
3537
#[allow(deprecated)]
3638
use super::v1;
3739
use super::v2;
@@ -42,8 +44,7 @@ impl <T> v2::OutputPin for T
4244
where
4345
T: v1::OutputPin,
4446
{
45-
// TODO: update to ! when never_type is stabilized
46-
type Error = ();
47+
type Error = Infallible;
4748

4849
fn set_low(&mut self) -> Result<(), Self::Error> {
4950
Ok(self.set_low())
@@ -81,8 +82,7 @@ impl <T> v2::InputPin for T
8182
where
8283
T: v1::InputPin
8384
{
84-
// TODO: update to ! when never_type is stabilized
85-
type Error = ();
85+
type Error = Infallible;
8686

8787
fn is_low(&self) -> Result<bool, Self::Error> {
8888
Ok(self.is_low())

src/lib.rs

+32-39
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,20 @@
9090
//! [`WouldBlock`]: https://docs.rs/nb/0.1.0/nb/enum.Error.html
9191
//!
9292
//! Some traits, like the one shown below, may expose possibly blocking APIs that can't fail. In
93-
//! those cases `nb::Result<_, Void>` is used.
93+
//! those cases `nb::Result<_, Infallible>` is used.
9494
//!
9595
//! ```
9696
//! extern crate nb;
97-
//! extern crate void;
9897
//!
99-
//! use void::Void;
98+
//! # use std as core;
99+
//! use core::convert::Infallible;
100100
//!
101101
//! /// A count down timer
102102
//! pub trait CountDown {
103103
//! // ..
104104
//!
105105
//! /// "waits" until the count down is over
106-
//! fn wait(&mut self) -> nb::Result<(), Void>;
106+
//! fn wait(&mut self) -> nb::Result<(), Infallible>;
107107
//! }
108108
//!
109109
//! # fn main() {}
@@ -223,11 +223,10 @@
223223
//! # }
224224
//!
225225
//! # mod stm32f30x_hal {
226-
//! # extern crate void;
227-
//! # use self::void::Void;
226+
//! # use std::convert::Infallible;
228227
//! # pub struct Serial1;
229228
//! # impl Serial1 {
230-
//! # pub fn write(&mut self, _: u8) -> ::nb::Result<(), Void> {
229+
//! # pub fn write(&mut self, _: u8) -> ::nb::Result<(), Infallible> {
231230
//! # Ok(())
232231
//! # }
233232
//! # }
@@ -242,7 +241,6 @@
242241
//! ```
243242
//! extern crate embedded_hal as hal;
244243
//! extern crate futures;
245-
//! extern crate void;
246244
//!
247245
//! #[macro_use(try_nb)]
248246
//! extern crate nb;
@@ -255,12 +253,12 @@
255253
//! };
256254
//! use futures::future::Loop;
257255
//! use stm32f30x_hal::{Led, Serial1, Timer6};
258-
//! use void::Void;
256+
//! use std::convert::Infallible;
259257
//!
260258
//! /// `futures` version of `CountDown.wait`
261259
//! ///
262260
//! /// This returns a future that must be polled to completion
263-
//! fn wait<T>(mut timer: T) -> impl Future<Item = T, Error = Void>
261+
//! fn wait<T>(mut timer: T) -> impl Future<Item = T, Error = Infallible>
264262
//! where
265263
//! T: hal::timer::CountDown,
266264
//! {
@@ -342,32 +340,31 @@
342340
//!
343341
//! // Event loop
344342
//! loop {
345-
//! blinky.poll().unwrap(); // NOTE(unwrap) E = Void
343+
//! blinky.poll().unwrap(); // NOTE(unwrap) E = Infallible
346344
//! loopback.poll().unwrap();
347345
//! # break;
348346
//! }
349347
//! }
350348
//!
351349
//! # mod stm32f30x_hal {
352-
//! # extern crate void;
353-
//! # use self::void::Void;
350+
//! # use std::convert::Infallible;
354351
//! # pub struct Timer6;
355352
//! # impl ::hal::timer::CountDown for Timer6 {
356353
//! # type Time = ();
357354
//! #
358355
//! # fn start<T>(&mut self, _: T) where T: Into<()> {}
359-
//! # fn wait(&mut self) -> ::nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
356+
//! # fn wait(&mut self) -> ::nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
360357
//! # }
361358
//! #
362359
//! # pub struct Serial1;
363360
//! # impl ::hal::serial::Read<u8> for Serial1 {
364-
//! # type Error = Void;
365-
//! # fn read(&mut self) -> ::nb::Result<u8, Void> { Err(::nb::Error::WouldBlock) }
361+
//! # type Error = Infallible;
362+
//! # fn read(&mut self) -> ::nb::Result<u8, Infallible> { Err(::nb::Error::WouldBlock) }
366363
//! # }
367364
//! # impl ::hal::serial::Write<u8> for Serial1 {
368-
//! # type Error = Void;
369-
//! # fn flush(&mut self) -> ::nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
370-
//! # fn write(&mut self, _: u8) -> ::nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
365+
//! # type Error = Infallible;
366+
//! # fn flush(&mut self) -> ::nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
367+
//! # fn write(&mut self, _: u8) -> ::nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
371368
//! # }
372369
//! #
373370
//! # pub struct Led;
@@ -418,7 +415,7 @@
418415
//! loop {
419416
//! // `await!` means "suspend / yield here" instead of "block until
420417
//! // completion"
421-
//! await!(timer.wait()).unwrap(); // NOTE(unwrap) E = Void
418+
//! await!(timer.wait()).unwrap(); // NOTE(unwrap) E = Infallible
422419
//!
423420
//! state = !state;
424421
//!
@@ -446,16 +443,15 @@
446443
//! }
447444
//!
448445
//! # mod stm32f30x_hal {
449-
//! # extern crate void;
450-
//! # use self::void::Void;
446+
//! # use std::convert::Infallible;
451447
//! # pub struct Serial1;
452448
//! # impl Serial1 {
453-
//! # pub fn read(&mut self) -> ::nb::Result<u8, Void> { Err(::nb::Error::WouldBlock) }
454-
//! # pub fn write(&mut self, _: u8) -> ::nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
449+
//! # pub fn read(&mut self) -> ::nb::Result<u8, Infallible> { Err(::nb::Error::WouldBlock) }
450+
//! # pub fn write(&mut self, _: u8) -> ::nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
455451
//! # }
456452
//! # pub struct Timer6;
457453
//! # impl Timer6 {
458-
//! # pub fn wait(&mut self) -> ::nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
454+
//! # pub fn wait(&mut self) -> ::nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
459455
//! # }
460456
//! # pub struct Led;
461457
//! # impl Led {
@@ -594,16 +590,16 @@
594590
//! - Buffered serial interface with periodic flushing in interrupt handler
595591
//!
596592
//! ```
593+
//! # use std as core;
597594
//! extern crate embedded_hal as hal;
598595
//! extern crate nb;
599-
//! extern crate void;
600596
//!
601597
//! use hal::prelude::*;
602-
//! use void::Void;
598+
//! use core::convert::Infallible;
603599
//!
604600
//! fn flush<S>(serial: &mut S, cb: &mut CircularBuffer)
605601
//! where
606-
//! S: hal::serial::Write<u8, Error = Void>,
602+
//! S: hal::serial::Write<u8, Error = Infallible>,
607603
//! {
608604
//! loop {
609605
//! if let Some(byte) = cb.peek() {
@@ -668,9 +664,9 @@
668664
//! # }
669665
//! # struct Serial1;
670666
//! # impl ::hal::serial::Write<u8> for Serial1 {
671-
//! # type Error = Void;
672-
//! # fn write(&mut self, _: u8) -> nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
673-
//! # fn flush(&mut self) -> nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
667+
//! # type Error = Infallible;
668+
//! # fn write(&mut self, _: u8) -> nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
669+
//! # fn flush(&mut self) -> nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
674670
//! # }
675671
//! # struct CircularBuffer;
676672
//! # impl CircularBuffer {
@@ -687,7 +683,6 @@
687683

688684
#[macro_use]
689685
extern crate nb;
690-
extern crate void;
691686

692687
pub mod adc;
693688
pub mod blocking;
@@ -731,8 +726,7 @@ pub mod watchdog;
731726
/// println!("Period: {} ms", period);
732727
/// }
733728
///
734-
/// # extern crate void;
735-
/// # use void::Void;
729+
/// # use std::convert::Infallible;
736730
/// # struct MilliSeconds(u32);
737731
/// # trait U32Ext { fn ms(self) -> MilliSeconds; }
738732
/// # impl U32Ext for u32 { fn ms(self) -> MilliSeconds { MilliSeconds(self) } }
@@ -741,9 +735,9 @@ pub mod watchdog;
741735
/// # impl hal::Capture for Capture1 {
742736
/// # type Capture = u16;
743737
/// # type Channel = Channel;
744-
/// # type Error = Void;
738+
/// # type Error = Infallible;
745739
/// # type Time = MilliSeconds;
746-
/// # fn capture(&mut self, _: Channel) -> ::nb::Result<u16, Void> { Ok(0) }
740+
/// # fn capture(&mut self, _: Channel) -> ::nb::Result<u16, Infallible> { Ok(0) }
747741
/// # fn disable(&mut self, _: Channel) { unimplemented!() }
748742
/// # fn enable(&mut self, _: Channel) { unimplemented!() }
749743
/// # fn get_resolution(&self) -> MilliSeconds { unimplemented!() }
@@ -948,8 +942,7 @@ pub trait PwmPin {
948942
/// println!("Speed: {} pulses per second", speed);
949943
/// }
950944
///
951-
/// # extern crate void;
952-
/// # use void::Void;
945+
/// # use std::convert::Infallible;
953946
/// # struct Seconds(u32);
954947
/// # trait U32Ext { fn s(self) -> Seconds; }
955948
/// # impl U32Ext for u32 { fn s(self) -> Seconds { Seconds(self) } }
@@ -963,7 +956,7 @@ pub trait PwmPin {
963956
/// # impl hal::timer::CountDown for Timer6 {
964957
/// # type Time = Seconds;
965958
/// # fn start<T>(&mut self, _: T) where T: Into<Seconds> {}
966-
/// # fn wait(&mut self) -> ::nb::Result<(), Void> { Ok(()) }
959+
/// # fn wait(&mut self) -> ::nb::Result<(), Infallible> { Ok(()) }
967960
/// # }
968961
/// ```
969962
#[cfg(feature = "unproven")]

src/timer.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Timers
22
33
use nb;
4-
use void::Void;
4+
use core::convert::Infallible;
55

66
/// A count down timer
77
///
@@ -40,8 +40,7 @@ use void::Void;
4040
/// Led.off();
4141
/// }
4242
///
43-
/// # extern crate void;
44-
/// # use void::Void;
43+
/// # use std::convert::Infallible;
4544
/// # struct Seconds(u32);
4645
/// # trait U32Ext { fn s(self) -> Seconds; }
4746
/// # impl U32Ext for u32 { fn s(self) -> Seconds { Seconds(self) } }
@@ -54,7 +53,7 @@ use void::Void;
5453
/// # impl hal::timer::CountDown for Timer6 {
5554
/// # type Time = Seconds;
5655
/// # fn start<T>(&mut self, _: T) where T: Into<Seconds> {}
57-
/// # fn wait(&mut self) -> ::nb::Result<(), Void> { Ok(()) }
56+
/// # fn wait(&mut self) -> ::nb::Result<(), Infallible> { Ok(()) }
5857
/// # }
5958
/// ```
6059
pub trait CountDown {
@@ -74,7 +73,7 @@ pub trait CountDown {
7473
/// finishes.
7574
/// - Otherwise the behavior of calling `wait` after the last call returned `Ok` is UNSPECIFIED.
7675
/// Implementers are suggested to panic on this scenario to signal a programmer error.
77-
fn wait(&mut self) -> nb::Result<(), Void>;
76+
fn wait(&mut self) -> nb::Result<(), Infallible>;
7877
}
7978

8079
/// Marker trait that indicates that a timer is periodic

0 commit comments

Comments
 (0)