Skip to content

Commit ce85b01

Browse files
bors[bot]japaric
andcommitted
Merge #80
80: replace uses of ! with Void r=japaric a=japaric We are soon going to push for embedded *library* development on beta (1.27-beta) to minimize the number of unstable features used in the ecosystem and ease the transition towards *application* development on stable (1.28 or 1.29). Unfortunately `!` didn't make it into the beta release but we still need to make this crate work on beta because a lot of crates depend on it. So this PR replaces the single use of the `!` type (cf. `CountDown.wait`) with the equivalent, but stable, `Void` type. This is a [breaking-change]. Implementations of the `CountDown` trait will have to update the signature of `wait` to return `nb::Result<(), Void>`. cc @therealprof @hannobraun I'm going to publish v0.2.0 *soon* (ideally tonight). If there's some **breaking**, but *uncontroversial*, change that should be included in it let me know ASAP so we can land it before the release. Co-authored-by: Jorge Aparicio <[email protected]>
2 parents 0bbb915 + ec1d608 commit ce85b01

File tree

8 files changed

+86
-45
lines changed

8 files changed

+86
-45
lines changed

.travis.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ language: rust
22

33
matrix:
44
include:
5+
- env: TARGET=x86_64-unknown-linux-gnu
6+
7+
- env: TARGET=thumbv6m-none-eabi
8+
rust: beta
9+
10+
- env: TARGET=thumbv7m-none-eabi
11+
rust: beta
12+
513
- env: TARGET=x86_64-unknown-linux-gnu
614
rust: nightly
715

@@ -25,9 +33,8 @@ before_cache:
2533

2634
branches:
2735
only:
28-
- auto
29-
- master
30-
- try
36+
- staging
37+
- trying
3138

3239
notifications:
3340
email:

CHANGELOG.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [v0.2.0] - 2018-05-11
11+
12+
### Changed
13+
14+
- [breaking-change] The signature of `CountDown.wait` changed; it now returns `nb::Result<(),
15+
Void>`. Where [`Void`] is the stable alternative to the never type, `!`, provided by the stable
16+
[`void`] crate. Implementations of the `CountDown` trait will have to be updated to use the new
17+
signature. With this change this crate compiles on the stable and beta channels.
18+
19+
[`Void`]: https://docs.rs/void/1.0.2/void/enum.Void.html
20+
[`void`]: https://crates.io/crates/void
21+
1022
## [v0.1.2] - 2018-02-14
1123

1224
### Added
@@ -23,6 +35,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2335

2436
Initial release
2537

26-
[Unreleased]: https://github.com/japaric/embedded-hal/compare/v0.1.2...HEAD
38+
[Unreleased]: https://github.com/japaric/embedded-hal/compare/v0.2.0...HEAD
39+
[v0.2.0]: https://github.com/japaric/embedded-hal/compare/v0.1.2...v0.2.0
2740
[v0.1.2]: https://github.com/japaric/embedded-hal/compare/v0.1.1...v0.1.2
2841
[v0.1.1]: https://github.com/japaric/embedded-hal/compare/v0.1.0...v0.1.1

Cargo.toml

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

16+
[dependencies.void]
17+
default-features = false
18+
version = "1.0.2"
19+
1620
[dependencies.nb]
1721
version = "0.1.1"
1822

bors.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
status = [
2+
"continuous-integration/travis-ci/push",
3+
]

ci/install.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
set -euxo pipefail
22

33
main() {
4-
return
4+
if [ $TARGET != x86_64-unknown-linux-gnu ]; then
5+
rustup target add $TARGET
6+
fi
57
}
68

79
main

ci/script.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ set -euxo pipefail
22

33
main() {
44
cargo check --target $TARGET
5-
cargo test --target $TARGET --features unproven
5+
cargo check --target $TARGET --features unproven
6+
7+
if [ $TRAVIS_RUST_VERSION = nightly ]; then
8+
cargo test --target $TARGET --features unproven
9+
fi
610
}
711

812
main

src/lib.rs

+42-36
Original file line numberDiff line numberDiff line change
@@ -90,19 +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<_, !>` is used.
93+
//! those cases `nb::Result<_, Void>` is used.
9494
//!
9595
//! ```
96-
//! #![feature(never_type)]
97-
//!
9896
//! extern crate nb;
97+
//! extern crate void;
98+
//!
99+
//! use void::Void;
99100
//!
100101
//! /// A count down timer
101102
//! pub trait CountDown {
102103
//! // ..
103104
//!
104105
//! /// "waits" until the count down is over
105-
//! fn wait(&mut self) -> nb::Result<(), !>;
106+
//! fn wait(&mut self) -> nb::Result<(), Void>;
106107
//! }
107108
//!
108109
//! # fn main() {}
@@ -201,7 +202,6 @@
201202
//! fashion:
202203
//!
203204
//! ```
204-
//! # #![feature(never_type)]
205205
//! extern crate embedded_hal;
206206
//! #[macro_use(block)]
207207
//! extern crate nb;
@@ -223,9 +223,11 @@
223223
//! # }
224224
//!
225225
//! # mod stm32f30x_hal {
226+
//! # extern crate void;
227+
//! # use self::void::Void;
226228
//! # pub struct Serial1;
227229
//! # impl Serial1 {
228-
//! # pub fn write(&mut self, _: u8) -> ::nb::Result<(), !> {
230+
//! # pub fn write(&mut self, _: u8) -> ::nb::Result<(), Void> {
229231
//! # Ok(())
230232
//! # }
231233
//! # }
@@ -238,11 +240,9 @@
238240
//! second. Second task: loop back data over the serial interface.
239241
//!
240242
//! ```
241-
//! #![feature(conservative_impl_trait)]
242-
//! #![feature(never_type)]
243-
//!
244243
//! extern crate embedded_hal as hal;
245244
//! extern crate futures;
245+
//! extern crate void;
246246
//!
247247
//! #[macro_use(try_nb)]
248248
//! extern crate nb;
@@ -255,11 +255,12 @@
255255
//! };
256256
//! use futures::future::Loop;
257257
//! use stm32f30x_hal::{Led, Serial1, Timer6};
258+
//! use void::Void;
258259
//!
259260
//! /// `futures` version of `CountDown.wait`
260261
//! ///
261262
//! /// This returns a future that must be polled to completion
262-
//! fn wait<T>(mut timer: T) -> impl Future<Item = T, Error = !>
263+
//! fn wait<T>(mut timer: T) -> impl Future<Item = T, Error = Void>
263264
//! where
264265
//! T: hal::timer::CountDown,
265266
//! {
@@ -341,30 +342,32 @@
341342
//!
342343
//! // Event loop
343344
//! loop {
344-
//! blinky.poll().unwrap(); // NOTE(unwrap) E = !
345+
//! blinky.poll().unwrap(); // NOTE(unwrap) E = Void
345346
//! loopback.poll().unwrap();
346347
//! # break;
347348
//! }
348349
//! }
349350
//!
350351
//! # mod stm32f30x_hal {
352+
//! # extern crate void;
353+
//! # use self::void::Void;
351354
//! # pub struct Timer6;
352355
//! # impl ::hal::timer::CountDown for Timer6 {
353356
//! # type Time = ();
354357
//! #
355358
//! # fn start<T>(&mut self, _: T) where T: Into<()> {}
356-
//! # fn wait(&mut self) -> ::nb::Result<(), !> { Err(::nb::Error::WouldBlock) }
359+
//! # fn wait(&mut self) -> ::nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
357360
//! # }
358361
//! #
359362
//! # pub struct Serial1;
360363
//! # impl ::hal::serial::Read<u8> for Serial1 {
361-
//! # type Error = !;
362-
//! # fn read(&mut self) -> ::nb::Result<u8, !> { Err(::nb::Error::WouldBlock) }
364+
//! # type Error = Void;
365+
//! # fn read(&mut self) -> ::nb::Result<u8, Void> { Err(::nb::Error::WouldBlock) }
363366
//! # }
364367
//! # impl ::hal::serial::Write<u8> for Serial1 {
365-
//! # type Error = !;
366-
//! # fn flush(&mut self) -> ::nb::Result<(), !> { Err(::nb::Error::WouldBlock) }
367-
//! # fn write(&mut self, _: u8) -> ::nb::Result<(), !> { Err(::nb::Error::WouldBlock) }
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) }
368371
//! # }
369372
//! #
370373
//! # pub struct Led;
@@ -382,7 +385,6 @@
382385
//! ```
383386
//! #![feature(generator_trait)]
384387
//! #![feature(generators)]
385-
//! # #![feature(never_type)]
386388
//!
387389
//! extern crate embedded_hal as hal;
388390
//!
@@ -415,7 +417,7 @@
415417
//! loop {
416418
//! // `await!` means "suspend / yield here" instead of "block until
417419
//! // completion"
418-
//! await!(timer.wait()).unwrap(); // NOTE(unwrap) E = !
420+
//! await!(timer.wait()).unwrap(); // NOTE(unwrap) E = Void
419421
//!
420422
//! state = !state;
421423
//!
@@ -436,21 +438,23 @@
436438
//!
437439
//! // Event loop
438440
//! loop {
439-
//! blinky.resume();
440-
//! loopback.resume();
441+
//! unsafe { blinky.resume(); }
442+
//! unsafe { loopback.resume(); }
441443
//! # break;
442444
//! }
443445
//! }
444446
//!
445447
//! # mod stm32f30x_hal {
448+
//! # extern crate void;
449+
//! # use self::void::Void;
446450
//! # pub struct Serial1;
447451
//! # impl Serial1 {
448-
//! # pub fn read(&mut self) -> ::nb::Result<u8, !> { Err(::nb::Error::WouldBlock) }
449-
//! # pub fn write(&mut self, _: u8) -> ::nb::Result<(), !> { Err(::nb::Error::WouldBlock) }
452+
//! # pub fn read(&mut self) -> ::nb::Result<u8, Void> { Err(::nb::Error::WouldBlock) }
453+
//! # pub fn write(&mut self, _: u8) -> ::nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
450454
//! # }
451455
//! # pub struct Timer6;
452456
//! # impl Timer6 {
453-
//! # pub fn wait(&mut self) -> ::nb::Result<(), !> { Err(::nb::Error::WouldBlock) }
457+
//! # pub fn wait(&mut self) -> ::nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
454458
//! # }
455459
//! # pub struct Led;
456460
//! # impl Led {
@@ -589,15 +593,16 @@
589593
//! - Buffered serial interface with periodic flushing in interrupt handler
590594
//!
591595
//! ```
592-
//! # #![feature(never_type)]
593596
//! extern crate embedded_hal as hal;
594597
//! extern crate nb;
598+
//! extern crate void;
595599
//!
596600
//! use hal::prelude::*;
601+
//! use void::Void;
597602
//!
598603
//! fn flush<S>(serial: &mut S, cb: &mut CircularBuffer)
599604
//! where
600-
//! S: hal::serial::Write<u8, Error = !>,
605+
//! S: hal::serial::Write<u8, Error = Void>,
601606
//! {
602607
//! loop {
603608
//! if let Some(byte) = cb.peek() {
@@ -662,9 +667,9 @@
662667
//! # }
663668
//! # struct Serial1;
664669
//! # impl ::hal::serial::Write<u8> for Serial1 {
665-
//! # type Error = !;
666-
//! # fn write(&mut self, _: u8) -> nb::Result<(), !> { Err(::nb::Error::WouldBlock) }
667-
//! # fn flush(&mut self) -> nb::Result<(), !> { Err(::nb::Error::WouldBlock) }
670+
//! # type Error = Void;
671+
//! # fn write(&mut self, _: u8) -> nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
672+
//! # fn flush(&mut self) -> nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
668673
//! # }
669674
//! # struct CircularBuffer;
670675
//! # impl CircularBuffer {
@@ -678,11 +683,11 @@
678683
679684
#![deny(missing_docs)]
680685
#![deny(warnings)]
681-
#![feature(never_type)]
682686
#![no_std]
683687

684688
#[macro_use]
685689
extern crate nb;
690+
extern crate void;
686691

687692
pub mod blocking;
688693
pub mod digital;
@@ -699,8 +704,6 @@ pub mod timer;
699704
/// / events
700705
///
701706
/// ```
702-
/// # #![feature(never_type)]
703-
///
704707
/// extern crate embedded_hal as hal;
705708
/// #[macro_use(block)]
706709
/// extern crate nb;
@@ -723,6 +726,8 @@ pub mod timer;
723726
/// println!("Period: {} ms", period);
724727
/// }
725728
///
729+
/// # extern crate void;
730+
/// # use void::Void;
726731
/// # struct MilliSeconds(u32);
727732
/// # trait U32Ext { fn ms(self) -> MilliSeconds; }
728733
/// # impl U32Ext for u32 { fn ms(self) -> MilliSeconds { MilliSeconds(self) } }
@@ -731,9 +736,9 @@ pub mod timer;
731736
/// # impl hal::Capture for Capture1 {
732737
/// # type Capture = u16;
733738
/// # type Channel = Channel;
734-
/// # type Error = !;
739+
/// # type Error = Void;
735740
/// # type Time = MilliSeconds;
736-
/// # fn capture(&mut self, _: Channel) -> ::nb::Result<u16, !> { Ok(0) }
741+
/// # fn capture(&mut self, _: Channel) -> ::nb::Result<u16, Void> { Ok(0) }
737742
/// # fn disable(&mut self, _: Channel) { unimplemented!() }
738743
/// # fn enable(&mut self, _: Channel) { unimplemented!() }
739744
/// # fn get_resolution(&self) -> MilliSeconds { unimplemented!() }
@@ -908,7 +913,6 @@ pub trait PwmPin {
908913
/// You can use this interface to measure the speed of a motor
909914
///
910915
/// ```
911-
/// # #![feature(never_type)]
912916
/// extern crate embedded_hal as hal;
913917
/// #[macro_use(block)]
914918
/// extern crate nb;
@@ -935,6 +939,8 @@ pub trait PwmPin {
935939
/// println!("Speed: {} pulses per second", speed);
936940
/// }
937941
///
942+
/// # extern crate void;
943+
/// # use void::Void;
938944
/// # struct Seconds(u32);
939945
/// # trait U32Ext { fn s(self) -> Seconds; }
940946
/// # impl U32Ext for u32 { fn s(self) -> Seconds { Seconds(self) } }
@@ -948,7 +954,7 @@ pub trait PwmPin {
948954
/// # impl hal::timer::CountDown for Timer6 {
949955
/// # type Time = Seconds;
950956
/// # fn start<T>(&mut self, _: T) where T: Into<Seconds> {}
951-
/// # fn wait(&mut self) -> ::nb::Result<(), !> { Ok(()) }
957+
/// # fn wait(&mut self) -> ::nb::Result<(), Void> { Ok(()) }
952958
/// # }
953959
/// ```
954960
#[cfg(feature = "unproven")]

src/timer.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Timers
22
33
use nb;
4+
use void::Void;
45

56
/// A count down timer
67
///
@@ -17,7 +18,6 @@ use nb;
1718
/// You can use this timer to create delays
1819
///
1920
/// ```
20-
/// # #![feature(never_type)]
2121
/// extern crate embedded_hal as hal;
2222
/// #[macro_use(block)]
2323
/// extern crate nb;
@@ -40,6 +40,8 @@ use nb;
4040
/// Led.off();
4141
/// }
4242
///
43+
/// # extern crate void;
44+
/// # use void::Void;
4345
/// # struct Seconds(u32);
4446
/// # trait U32Ext { fn s(self) -> Seconds; }
4547
/// # impl U32Ext for u32 { fn s(self) -> Seconds { Seconds(self) } }
@@ -52,7 +54,7 @@ use nb;
5254
/// # impl hal::timer::CountDown for Timer6 {
5355
/// # type Time = Seconds;
5456
/// # fn start<T>(&mut self, _: T) where T: Into<Seconds> {}
55-
/// # fn wait(&mut self) -> ::nb::Result<(), !> { Ok(()) }
57+
/// # fn wait(&mut self) -> ::nb::Result<(), Void> { Ok(()) }
5658
/// # }
5759
/// ```
5860
pub trait CountDown {
@@ -72,7 +74,7 @@ pub trait CountDown {
7274
/// finishes.
7375
/// - Otherwise the behavior of calling `wait` after the last call returned `Ok` is UNSPECIFIED.
7476
/// Implementers are suggested to panic on this scenario to signal a programmer error.
75-
fn wait(&mut self) -> nb::Result<(), !>;
77+
fn wait(&mut self) -> nb::Result<(), Void>;
7678
}
7779

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

0 commit comments

Comments
 (0)