Skip to content

Make the digital::{v1, v2}::InputPin traits proven #164

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

Merged
merged 3 commits into from
Nov 17, 2019
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).


### Changed

- The current versions of `InputPin` have been proven. These are `digital::v1::InputPin`
and `digital::v2::InputPin`.

## [v0.2.3] - 2019-05-09

Expand Down
3 changes: 0 additions & 3 deletions src/digital/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,8 @@ pub mod toggleable {

/// Single digital input pin
///
/// *This trait is available if embedded-hal is built with the `"unproven"` feature.*
///
/// *This version of the trait is now deprecated. Please use the new `InputPin` trait in
/// `digital::v2::InputPin`*.
#[cfg(feature = "unproven")]
pub trait InputPin {
/// Is the input pin high?
fn is_high(&self) -> bool;
Expand Down
12 changes: 0 additions & 12 deletions src/digital/v1_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,10 @@ where

/// Wrapper to allow fallible `v2::InputPin` traits to be converted to `v1::InputPin` traits
/// where errors will panic.
#[cfg(feature = "unproven")]
pub struct OldInputPin<T> {
pin: T,
}

#[cfg(feature = "unproven")]
impl <T, E> OldInputPin<T>
where
T: v2::OutputPin<Error=E>,
Expand All @@ -126,7 +124,6 @@ where

}

#[cfg(feature = "unproven")]
impl <T, E> From<T> for OldInputPin<T>
where
T: v2::InputPin<Error=E>,
Expand All @@ -139,7 +136,6 @@ where

/// Implementation of `v1::InputPin` trait for `v2::InputPin` fallible pins
/// where errors will panic.
#[cfg(feature = "unproven")]
#[allow(deprecated)]
impl <T, E> v1::InputPin for OldInputPin<T>
where
Expand Down Expand Up @@ -224,15 +220,12 @@ mod tests {
o.set_high();
}

#[cfg(feature = "unproven")]
use crate::digital::v1::InputPin;

#[cfg(feature = "unproven")]
struct NewInputPinImpl {
state: Result<bool, ()>,
}

#[cfg(feature = "unproven")]
impl v2::InputPin for NewInputPinImpl {
type Error = ();

Expand All @@ -244,13 +237,11 @@ mod tests {
}
}

#[cfg(feature = "unproven")]
#[allow(deprecated)]
struct OldInputPinConsumer<T: v1::InputPin> {
_pin: T,
}

#[cfg(feature = "unproven")]
#[allow(deprecated)]
impl <T>OldInputPinConsumer<T>
where T: v1::InputPin
Expand All @@ -260,14 +251,12 @@ mod tests {
}
}

#[cfg(feature = "unproven")]
#[test]
fn v1_v2_input_explicit() {
let i = NewInputPinImpl{state: Ok(false)};
let _c: OldInputPinConsumer<OldInputPin<_>> = OldInputPinConsumer::new(i.into());
}

#[cfg(feature = "unproven")]
#[test]
fn v1_v2_input_state() {
let i: OldInputPin<_> = NewInputPinImpl{state: Ok(false)}.into();
Expand All @@ -276,7 +265,6 @@ mod tests {
assert_eq!(i.is_high(), false);
}

#[cfg(feature = "unproven")]
#[test]
#[should_panic]
fn v1_v2_input_panic() {
Expand Down
3 changes: 0 additions & 3 deletions src/digital/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ pub mod toggleable {
}

/// Single digital input pin
///
/// *This trait is available if embedded-hal is built with the `"unproven"` feature.*
#[cfg(feature = "unproven")]
pub trait InputPin {
/// Error type
type Error;
Expand Down
9 changes: 1 addition & 8 deletions src/digital/v2_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ where
impl<T> v2::toggleable::Default for T where T: v1::toggleable::Default {}

/// Implementation of fallible `v2::InputPin` for `v1::InputPin` digital traits
#[cfg(feature = "unproven")]
#[allow(deprecated)]
impl <T> v2::InputPin for T
where
Expand Down Expand Up @@ -176,13 +175,11 @@ mod tests {
assert_eq!(o.state, false);
}

#[cfg(feature = "unproven")]
#[allow(deprecated)]
struct OldInputPinImpl {
state: bool
}

#[cfg(feature = "unproven")]
#[allow(deprecated)]
impl v1::InputPin for OldInputPinImpl {
fn is_low(&self) -> bool {
Expand All @@ -193,32 +190,28 @@ mod tests {
}
}

#[cfg(feature = "unproven")]
struct NewInputPinConsumer<T: v2::InputPin> {
_pin: T,
}

#[cfg(feature = "unproven")]
impl <T>NewInputPinConsumer<T>
where T: v2::InputPin {
pub fn new(pin: T) -> NewInputPinConsumer<T> {
NewInputPinConsumer{ _pin: pin }
}
}

#[cfg(feature = "unproven")]
#[test]
fn v2_v1_input_implicit() {
let i = OldInputPinImpl{state: false};
let _c = NewInputPinConsumer::new(i);
}

#[cfg(feature = "unproven")]
#[test]
fn v2_v1_input_state() {
let mut i = OldInputPinImpl{state: false};

assert_eq!(v2::InputPin::is_high(&mut i).unwrap(), false);
assert_eq!(v2::InputPin::is_low(&mut i).unwrap(), true);
}
}
}