Skip to content

Commit 7432e4a

Browse files
committed
Replace Void with core::convert::Infallible
1 parent 640a87e commit 7432e4a

File tree

4 files changed

+36
-49
lines changed

4 files changed

+36
-49
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 core::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/lib.rs

+30-39
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,19 @@
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 core::convert::Infallible;
10099
//!
101100
//! /// A count down timer
102101
//! pub trait CountDown {
103102
//! // ..
104103
//!
105104
//! /// "waits" until the count down is over
106-
//! fn wait(&mut self) -> nb::Result<(), Void>;
105+
//! fn wait(&mut self) -> nb::Result<(), Infallible>;
107106
//! }
108107
//!
109108
//! # fn main() {}
@@ -223,11 +222,10 @@
223222
//! # }
224223
//!
225224
//! # mod stm32f30x_hal {
226-
//! # extern crate void;
227-
//! # use self::void::Void;
225+
//! # use core::convert::Infallible;
228226
//! # pub struct Serial1;
229227
//! # impl Serial1 {
230-
//! # pub fn write(&mut self, _: u8) -> ::nb::Result<(), Void> {
228+
//! # pub fn write(&mut self, _: u8) -> ::nb::Result<(), Infallible> {
231229
//! # Ok(())
232230
//! # }
233231
//! # }
@@ -242,7 +240,6 @@
242240
//! ```
243241
//! extern crate embedded_hal as hal;
244242
//! extern crate futures;
245-
//! extern crate void;
246243
//!
247244
//! #[macro_use(try_nb)]
248245
//! extern crate nb;
@@ -255,12 +252,12 @@
255252
//! };
256253
//! use futures::future::Loop;
257254
//! use stm32f30x_hal::{Led, Serial1, Timer6};
258-
//! use void::Void;
255+
//! use core::convert::Infallible;
259256
//!
260257
//! /// `futures` version of `CountDown.wait`
261258
//! ///
262259
//! /// This returns a future that must be polled to completion
263-
//! fn wait<T>(mut timer: T) -> impl Future<Item = T, Error = Void>
260+
//! fn wait<T>(mut timer: T) -> impl Future<Item = T, Error = Infallible>
264261
//! where
265262
//! T: hal::timer::CountDown,
266263
//! {
@@ -342,32 +339,31 @@
342339
//!
343340
//! // Event loop
344341
//! loop {
345-
//! blinky.poll().unwrap(); // NOTE(unwrap) E = Void
342+
//! blinky.poll().unwrap(); // NOTE(unwrap) E = Infallible
346343
//! loopback.poll().unwrap();
347344
//! # break;
348345
//! }
349346
//! }
350347
//!
351348
//! # mod stm32f30x_hal {
352-
//! # extern crate void;
353-
//! # use self::void::Void;
349+
//! # use core::convert::Infallible;
354350
//! # pub struct Timer6;
355351
//! # impl ::hal::timer::CountDown for Timer6 {
356352
//! # type Time = ();
357353
//! #
358354
//! # fn start<T>(&mut self, _: T) where T: Into<()> {}
359-
//! # fn wait(&mut self) -> ::nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
355+
//! # fn wait(&mut self) -> ::nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
360356
//! # }
361357
//! #
362358
//! # pub struct Serial1;
363359
//! # impl ::hal::serial::Read<u8> for Serial1 {
364-
//! # type Error = Void;
365-
//! # fn read(&mut self) -> ::nb::Result<u8, Void> { Err(::nb::Error::WouldBlock) }
360+
//! # type Error = Infallible;
361+
//! # fn read(&mut self) -> ::nb::Result<u8, Infallible> { Err(::nb::Error::WouldBlock) }
366362
//! # }
367363
//! # 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) }
364+
//! # type Error = Infallible;
365+
//! # fn flush(&mut self) -> ::nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
366+
//! # fn write(&mut self, _: u8) -> ::nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
371367
//! # }
372368
//! #
373369
//! # pub struct Led;
@@ -418,7 +414,7 @@
418414
//! loop {
419415
//! // `await!` means "suspend / yield here" instead of "block until
420416
//! // completion"
421-
//! await!(timer.wait()).unwrap(); // NOTE(unwrap) E = Void
417+
//! await!(timer.wait()).unwrap(); // NOTE(unwrap) E = Infallible
422418
//!
423419
//! state = !state;
424420
//!
@@ -446,16 +442,15 @@
446442
//! }
447443
//!
448444
//! # mod stm32f30x_hal {
449-
//! # extern crate void;
450-
//! # use self::void::Void;
445+
//! # use core::convert::Infallible;
451446
//! # pub struct Serial1;
452447
//! # 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) }
448+
//! # pub fn read(&mut self) -> ::nb::Result<u8, Infallible> { Err(::nb::Error::WouldBlock) }
449+
//! # pub fn write(&mut self, _: u8) -> ::nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
455450
//! # }
456451
//! # pub struct Timer6;
457452
//! # impl Timer6 {
458-
//! # pub fn wait(&mut self) -> ::nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
453+
//! # pub fn wait(&mut self) -> ::nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
459454
//! # }
460455
//! # pub struct Led;
461456
//! # impl Led {
@@ -596,14 +591,13 @@
596591
//! ```
597592
//! extern crate embedded_hal as hal;
598593
//! extern crate nb;
599-
//! extern crate void;
600594
//!
601595
//! use hal::prelude::*;
602-
//! use void::Void;
596+
//! use core::convert::Infallible;
603597
//!
604598
//! fn flush<S>(serial: &mut S, cb: &mut CircularBuffer)
605599
//! where
606-
//! S: hal::serial::Write<u8, Error = Void>,
600+
//! S: hal::serial::Write<u8, Error = Infallible>,
607601
//! {
608602
//! loop {
609603
//! if let Some(byte) = cb.peek() {
@@ -668,9 +662,9 @@
668662
//! # }
669663
//! # struct Serial1;
670664
//! # 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) }
665+
//! # type Error = Infallible;
666+
//! # fn write(&mut self, _: u8) -> nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
667+
//! # fn flush(&mut self) -> nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) }
674668
//! # }
675669
//! # struct CircularBuffer;
676670
//! # impl CircularBuffer {
@@ -687,7 +681,6 @@
687681

688682
#[macro_use]
689683
extern crate nb;
690-
extern crate void;
691684

692685
pub mod adc;
693686
pub mod blocking;
@@ -731,8 +724,7 @@ pub mod watchdog;
731724
/// println!("Period: {} ms", period);
732725
/// }
733726
///
734-
/// # extern crate void;
735-
/// # use void::Void;
727+
/// # use core::convert::Infallible;
736728
/// # struct MilliSeconds(u32);
737729
/// # trait U32Ext { fn ms(self) -> MilliSeconds; }
738730
/// # impl U32Ext for u32 { fn ms(self) -> MilliSeconds { MilliSeconds(self) } }
@@ -741,9 +733,9 @@ pub mod watchdog;
741733
/// # impl hal::Capture for Capture1 {
742734
/// # type Capture = u16;
743735
/// # type Channel = Channel;
744-
/// # type Error = Void;
736+
/// # type Error = Infallible;
745737
/// # type Time = MilliSeconds;
746-
/// # fn capture(&mut self, _: Channel) -> ::nb::Result<u16, Void> { Ok(0) }
738+
/// # fn capture(&mut self, _: Channel) -> ::nb::Result<u16, Infallible> { Ok(0) }
747739
/// # fn disable(&mut self, _: Channel) { unimplemented!() }
748740
/// # fn enable(&mut self, _: Channel) { unimplemented!() }
749741
/// # fn get_resolution(&self) -> MilliSeconds { unimplemented!() }
@@ -948,8 +940,7 @@ pub trait PwmPin {
948940
/// println!("Speed: {} pulses per second", speed);
949941
/// }
950942
///
951-
/// # extern crate void;
952-
/// # use void::Void;
943+
/// # use core::convert::Infallible;
953944
/// # struct Seconds(u32);
954945
/// # trait U32Ext { fn s(self) -> Seconds; }
955946
/// # impl U32Ext for u32 { fn s(self) -> Seconds { Seconds(self) } }
@@ -963,7 +954,7 @@ pub trait PwmPin {
963954
/// # impl hal::timer::CountDown for Timer6 {
964955
/// # type Time = Seconds;
965956
/// # fn start<T>(&mut self, _: T) where T: Into<Seconds> {}
966-
/// # fn wait(&mut self) -> ::nb::Result<(), Void> { Ok(()) }
957+
/// # fn wait(&mut self) -> ::nb::Result<(), Infallible> { Ok(()) }
967958
/// # }
968959
/// ```
969960
#[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 core::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)