Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace uses of ! with Void #80

Merged
merged 2 commits into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ language: rust

matrix:
include:
- env: TARGET=x86_64-unknown-linux-gnu

- env: TARGET=thumbv6m-none-eabi
rust: beta

- env: TARGET=thumbv7m-none-eabi
rust: beta

- env: TARGET=x86_64-unknown-linux-gnu
rust: nightly

Expand All @@ -25,9 +33,8 @@ before_cache:

branches:
only:
- auto
- master
- try
- staging
- trying

notifications:
email:
Expand Down
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [v0.2.0] - 2018-05-11

### Changed

- [breaking-change] The signature of `CountDown.wait` changed; it now returns `nb::Result<(),
Void>`. Where [`Void`] is the stable alternative to the never type, `!`, provided by the stable
[`void`] crate. Implementations of the `CountDown` trait will have to be updated to use the new
signature. With this change this crate compiles on the stable and beta channels.

[`Void`]: https://docs.rs/void/1.0.2/void/enum.Void.html
[`void`]: https://crates.io/crates/void

## [v0.1.2] - 2018-02-14

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

Initial release

[Unreleased]: https://github.com/japaric/embedded-hal/compare/v0.1.2...HEAD
[Unreleased]: https://github.com/japaric/embedded-hal/compare/v0.2.0...HEAD
[v0.2.0]: https://github.com/japaric/embedded-hal/compare/v0.1.2...v0.2.0
[v0.1.2]: https://github.com/japaric/embedded-hal/compare/v0.1.1...v0.1.2
[v0.1.1]: https://github.com/japaric/embedded-hal/compare/v0.1.0...v0.1.1
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ readme = "README.md"
repository = "https://github.com/japaric/embedded-hal"
version = "0.1.2"

[dependencies.void]
default-features = false
version = "1.0.2"

[dependencies.nb]
version = "0.1.1"

Expand Down
3 changes: 3 additions & 0 deletions bors.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
status = [
"continuous-integration/travis-ci/push",
]
4 changes: 3 additions & 1 deletion ci/install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
set -euxo pipefail

main() {
return
if [ $TARGET != x86_64-unknown-linux-gnu ]; then
rustup target add $TARGET
fi
}

main
6 changes: 5 additions & 1 deletion ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ set -euxo pipefail

main() {
cargo check --target $TARGET
cargo test --target $TARGET --features unproven
cargo check --target $TARGET --features unproven

if [ $TRAVIS_RUST_VERSION = nightly ]; then
cargo test --target $TARGET --features unproven
fi
}

main
78 changes: 42 additions & 36 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,20 @@
//! [`WouldBlock`]: https://docs.rs/nb/0.1.0/nb/enum.Error.html
//!
//! Some traits, like the one shown below, may expose possibly blocking APIs that can't fail. In
//! those cases `nb::Result<_, !>` is used.
//! those cases `nb::Result<_, Void>` is used.
//!
//! ```
//! #![feature(never_type)]
//!
//! extern crate nb;
//! extern crate void;
//!
//! use void::Void;
//!
//! /// A count down timer
//! pub trait CountDown {
//! // ..
//!
//! /// "waits" until the count down is over
//! fn wait(&mut self) -> nb::Result<(), !>;
//! fn wait(&mut self) -> nb::Result<(), Void>;
//! }
//!
//! # fn main() {}
Expand Down Expand Up @@ -201,7 +202,6 @@
//! fashion:
//!
//! ```
//! # #![feature(never_type)]
//! extern crate embedded_hal;
//! #[macro_use(block)]
//! extern crate nb;
Expand All @@ -223,9 +223,11 @@
//! # }
//!
//! # mod stm32f30x_hal {
//! # extern crate void;
//! # use self::void::Void;
//! # pub struct Serial1;
//! # impl Serial1 {
//! # pub fn write(&mut self, _: u8) -> ::nb::Result<(), !> {
//! # pub fn write(&mut self, _: u8) -> ::nb::Result<(), Void> {
//! # Ok(())
//! # }
//! # }
Expand All @@ -238,11 +240,9 @@
//! second. Second task: loop back data over the serial interface.
//!
//! ```
//! #![feature(conservative_impl_trait)]
//! #![feature(never_type)]
//!
//! extern crate embedded_hal as hal;
//! extern crate futures;
//! extern crate void;
//!
//! #[macro_use(try_nb)]
//! extern crate nb;
Expand All @@ -255,11 +255,12 @@
//! };
//! use futures::future::Loop;
//! use stm32f30x_hal::{Led, Serial1, Timer6};
//! use void::Void;
//!
//! /// `futures` version of `CountDown.wait`
//! ///
//! /// This returns a future that must be polled to completion
//! fn wait<T>(mut timer: T) -> impl Future<Item = T, Error = !>
//! fn wait<T>(mut timer: T) -> impl Future<Item = T, Error = Void>
//! where
//! T: hal::timer::CountDown,
//! {
Expand Down Expand Up @@ -341,30 +342,32 @@
//!
//! // Event loop
//! loop {
//! blinky.poll().unwrap(); // NOTE(unwrap) E = !
//! blinky.poll().unwrap(); // NOTE(unwrap) E = Void
//! loopback.poll().unwrap();
//! # break;
//! }
//! }
//!
//! # mod stm32f30x_hal {
//! # extern crate void;
//! # use self::void::Void;
//! # pub struct Timer6;
//! # impl ::hal::timer::CountDown for Timer6 {
//! # type Time = ();
//! #
//! # fn start<T>(&mut self, _: T) where T: Into<()> {}
//! # fn wait(&mut self) -> ::nb::Result<(), !> { Err(::nb::Error::WouldBlock) }
//! # fn wait(&mut self) -> ::nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
//! # }
//! #
//! # pub struct Serial1;
//! # impl ::hal::serial::Read<u8> for Serial1 {
//! # type Error = !;
//! # fn read(&mut self) -> ::nb::Result<u8, !> { Err(::nb::Error::WouldBlock) }
//! # type Error = Void;
//! # fn read(&mut self) -> ::nb::Result<u8, Void> { Err(::nb::Error::WouldBlock) }
//! # }
//! # impl ::hal::serial::Write<u8> for Serial1 {
//! # type Error = !;
//! # fn flush(&mut self) -> ::nb::Result<(), !> { Err(::nb::Error::WouldBlock) }
//! # fn write(&mut self, _: u8) -> ::nb::Result<(), !> { Err(::nb::Error::WouldBlock) }
//! # type Error = Void;
//! # fn flush(&mut self) -> ::nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
//! # fn write(&mut self, _: u8) -> ::nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
//! # }
//! #
//! # pub struct Led;
Expand All @@ -382,7 +385,6 @@
//! ```
//! #![feature(generator_trait)]
//! #![feature(generators)]
//! # #![feature(never_type)]
//!
//! extern crate embedded_hal as hal;
//!
Expand Down Expand Up @@ -415,7 +417,7 @@
//! loop {
//! // `await!` means "suspend / yield here" instead of "block until
//! // completion"
//! await!(timer.wait()).unwrap(); // NOTE(unwrap) E = !
//! await!(timer.wait()).unwrap(); // NOTE(unwrap) E = Void
//!
//! state = !state;
//!
Expand All @@ -436,21 +438,23 @@
//!
//! // Event loop
//! loop {
//! blinky.resume();
//! loopback.resume();
//! unsafe { blinky.resume(); }
//! unsafe { loopback.resume(); }
//! # break;
//! }
//! }
//!
//! # mod stm32f30x_hal {
//! # extern crate void;
//! # use self::void::Void;
//! # pub struct Serial1;
//! # impl Serial1 {
//! # pub fn read(&mut self) -> ::nb::Result<u8, !> { Err(::nb::Error::WouldBlock) }
//! # pub fn write(&mut self, _: u8) -> ::nb::Result<(), !> { Err(::nb::Error::WouldBlock) }
//! # pub fn read(&mut self) -> ::nb::Result<u8, Void> { Err(::nb::Error::WouldBlock) }
//! # pub fn write(&mut self, _: u8) -> ::nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
//! # }
//! # pub struct Timer6;
//! # impl Timer6 {
//! # pub fn wait(&mut self) -> ::nb::Result<(), !> { Err(::nb::Error::WouldBlock) }
//! # pub fn wait(&mut self) -> ::nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
//! # }
//! # pub struct Led;
//! # impl Led {
Expand Down Expand Up @@ -589,15 +593,16 @@
//! - Buffered serial interface with periodic flushing in interrupt handler
//!
//! ```
//! # #![feature(never_type)]
//! extern crate embedded_hal as hal;
//! extern crate nb;
//! extern crate void;
//!
//! use hal::prelude::*;
//! use void::Void;
//!
//! fn flush<S>(serial: &mut S, cb: &mut CircularBuffer)
//! where
//! S: hal::serial::Write<u8, Error = !>,
//! S: hal::serial::Write<u8, Error = Void>,
//! {
//! loop {
//! if let Some(byte) = cb.peek() {
Expand Down Expand Up @@ -662,9 +667,9 @@
//! # }
//! # struct Serial1;
//! # impl ::hal::serial::Write<u8> for Serial1 {
//! # type Error = !;
//! # fn write(&mut self, _: u8) -> nb::Result<(), !> { Err(::nb::Error::WouldBlock) }
//! # fn flush(&mut self) -> nb::Result<(), !> { Err(::nb::Error::WouldBlock) }
//! # type Error = Void;
//! # fn write(&mut self, _: u8) -> nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
//! # fn flush(&mut self) -> nb::Result<(), Void> { Err(::nb::Error::WouldBlock) }
//! # }
//! # struct CircularBuffer;
//! # impl CircularBuffer {
Expand All @@ -678,11 +683,11 @@

#![deny(missing_docs)]
#![deny(warnings)]
#![feature(never_type)]
#![no_std]

#[macro_use]
extern crate nb;
extern crate void;

pub mod blocking;
pub mod digital;
Expand All @@ -699,8 +704,6 @@ pub mod timer;
/// / events
///
/// ```
/// # #![feature(never_type)]
///
/// extern crate embedded_hal as hal;
/// #[macro_use(block)]
/// extern crate nb;
Expand All @@ -723,6 +726,8 @@ pub mod timer;
/// println!("Period: {} ms", period);
/// }
///
/// # extern crate void;
/// # use void::Void;
/// # struct MilliSeconds(u32);
/// # trait U32Ext { fn ms(self) -> MilliSeconds; }
/// # impl U32Ext for u32 { fn ms(self) -> MilliSeconds { MilliSeconds(self) } }
Expand All @@ -731,9 +736,9 @@ pub mod timer;
/// # impl hal::Capture for Capture1 {
/// # type Capture = u16;
/// # type Channel = Channel;
/// # type Error = !;
/// # type Error = Void;
/// # type Time = MilliSeconds;
/// # fn capture(&mut self, _: Channel) -> ::nb::Result<u16, !> { Ok(0) }
/// # fn capture(&mut self, _: Channel) -> ::nb::Result<u16, Void> { Ok(0) }
/// # fn disable(&mut self, _: Channel) { unimplemented!() }
/// # fn enable(&mut self, _: Channel) { unimplemented!() }
/// # fn get_resolution(&self) -> MilliSeconds { unimplemented!() }
Expand Down Expand Up @@ -908,7 +913,6 @@ pub trait PwmPin {
/// You can use this interface to measure the speed of a motor
///
/// ```
/// # #![feature(never_type)]
/// extern crate embedded_hal as hal;
/// #[macro_use(block)]
/// extern crate nb;
Expand All @@ -935,6 +939,8 @@ pub trait PwmPin {
/// println!("Speed: {} pulses per second", speed);
/// }
///
/// # extern crate void;
/// # use void::Void;
/// # struct Seconds(u32);
/// # trait U32Ext { fn s(self) -> Seconds; }
/// # impl U32Ext for u32 { fn s(self) -> Seconds { Seconds(self) } }
Expand All @@ -948,7 +954,7 @@ pub trait PwmPin {
/// # impl hal::timer::CountDown for Timer6 {
/// # type Time = Seconds;
/// # fn start<T>(&mut self, _: T) where T: Into<Seconds> {}
/// # fn wait(&mut self) -> ::nb::Result<(), !> { Ok(()) }
/// # fn wait(&mut self) -> ::nb::Result<(), Void> { Ok(()) }
/// # }
/// ```
#[cfg(feature = "unproven")]
Expand Down
8 changes: 5 additions & 3 deletions src/timer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Timers

use nb;
use void::Void;

/// A count down timer
///
Expand All @@ -17,7 +18,6 @@ use nb;
/// You can use this timer to create delays
///
/// ```
/// # #![feature(never_type)]
/// extern crate embedded_hal as hal;
/// #[macro_use(block)]
/// extern crate nb;
Expand All @@ -40,6 +40,8 @@ use nb;
/// Led.off();
/// }
///
/// # extern crate void;
/// # use void::Void;
/// # struct Seconds(u32);
/// # trait U32Ext { fn s(self) -> Seconds; }
/// # impl U32Ext for u32 { fn s(self) -> Seconds { Seconds(self) } }
Expand All @@ -52,7 +54,7 @@ use nb;
/// # impl hal::timer::CountDown for Timer6 {
/// # type Time = Seconds;
/// # fn start<T>(&mut self, _: T) where T: Into<Seconds> {}
/// # fn wait(&mut self) -> ::nb::Result<(), !> { Ok(()) }
/// # fn wait(&mut self) -> ::nb::Result<(), Void> { Ok(()) }
/// # }
/// ```
pub trait CountDown {
Expand All @@ -72,7 +74,7 @@ pub trait CountDown {
/// finishes.
/// - Otherwise the behavior of calling `wait` after the last call returned `Ok` is UNSPECIFIED.
/// Implementers are suggested to panic on this scenario to signal a programmer error.
fn wait(&mut self) -> nb::Result<(), !>;
fn wait(&mut self) -> nb::Result<(), Void>;
}

/// Marker trait that indicates that a timer is periodic
Expand Down