From 1dad061022e1b1f069e28c1795bbbc8a331bc5d7 Mon Sep 17 00:00:00 2001 From: Nils VAN ZUIJLEN Date: Sun, 17 Nov 2019 20:33:25 +0100 Subject: [PATCH 1/3] Makes the digital::v2::InputPin trait proven See #41 for more details about this trait. Removes the feature flag from v2 implementation Keeps it on v1 because it would not make sense to prove a deprecated feature. --- src/digital/v1_compat.rs | 4 ++++ src/digital/v2.rs | 3 --- src/digital/v2_compat.rs | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/digital/v1_compat.rs b/src/digital/v1_compat.rs index 9de6e93ee..1c7796ff9 100644 --- a/src/digital/v1_compat.rs +++ b/src/digital/v1_compat.rs @@ -108,6 +108,8 @@ where /// Wrapper to allow fallible `v2::InputPin` traits to be converted to `v1::InputPin` traits /// where errors will panic. +/// +/// Available behind `"unproven"` feature because `v1::InputPin` is #[cfg(feature = "unproven")] pub struct OldInputPin { pin: T, @@ -139,6 +141,8 @@ where /// Implementation of `v1::InputPin` trait for `v2::InputPin` fallible pins /// where errors will panic. +/// +/// Available behind `"unproven"` feature because `v1::InputPin` is #[cfg(feature = "unproven")] #[allow(deprecated)] impl v1::InputPin for OldInputPin diff --git a/src/digital/v2.rs b/src/digital/v2.rs index d8f3cb35e..b8ccf2740 100644 --- a/src/digital/v2.rs +++ b/src/digital/v2.rs @@ -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; diff --git a/src/digital/v2_compat.rs b/src/digital/v2_compat.rs index 8531d68d7..4ae1da9a2 100644 --- a/src/digital/v2_compat.rs +++ b/src/digital/v2_compat.rs @@ -76,6 +76,8 @@ where impl v2::toggleable::Default for T where T: v1::toggleable::Default {} /// Implementation of fallible `v2::InputPin` for `v1::InputPin` digital traits +/// +/// Available behind `"unproven"` feature because `v1::InputPin` is #[cfg(feature = "unproven")] #[allow(deprecated)] impl v2::InputPin for T From bea9bb6577c5f30d28b212d25882d93b770fe50b Mon Sep 17 00:00:00 2001 From: Nils VAN ZUIJLEN Date: Sun, 17 Nov 2019 18:09:18 +0100 Subject: [PATCH 2/3] Make the digital::v1::InputPin proven Side effect: make the compat traits proven --- src/digital/v1.rs | 3 --- src/digital/v1_compat.rs | 16 ---------------- src/digital/v2_compat.rs | 11 +---------- 3 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/digital/v1.rs b/src/digital/v1.rs index d7bbfacaa..9c0678b10 100644 --- a/src/digital/v1.rs +++ b/src/digital/v1.rs @@ -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; diff --git a/src/digital/v1_compat.rs b/src/digital/v1_compat.rs index 1c7796ff9..a6689186c 100644 --- a/src/digital/v1_compat.rs +++ b/src/digital/v1_compat.rs @@ -108,14 +108,10 @@ where /// Wrapper to allow fallible `v2::InputPin` traits to be converted to `v1::InputPin` traits /// where errors will panic. -/// -/// Available behind `"unproven"` feature because `v1::InputPin` is -#[cfg(feature = "unproven")] pub struct OldInputPin { pin: T, } -#[cfg(feature = "unproven")] impl OldInputPin where T: v2::OutputPin, @@ -128,7 +124,6 @@ where } -#[cfg(feature = "unproven")] impl From for OldInputPin where T: v2::InputPin, @@ -141,9 +136,6 @@ where /// Implementation of `v1::InputPin` trait for `v2::InputPin` fallible pins /// where errors will panic. -/// -/// Available behind `"unproven"` feature because `v1::InputPin` is -#[cfg(feature = "unproven")] #[allow(deprecated)] impl v1::InputPin for OldInputPin where @@ -228,15 +220,12 @@ mod tests { o.set_high(); } - #[cfg(feature = "unproven")] use crate::digital::v1::InputPin; - #[cfg(feature = "unproven")] struct NewInputPinImpl { state: Result, } - #[cfg(feature = "unproven")] impl v2::InputPin for NewInputPinImpl { type Error = (); @@ -248,13 +237,11 @@ mod tests { } } - #[cfg(feature = "unproven")] #[allow(deprecated)] struct OldInputPinConsumer { _pin: T, } - #[cfg(feature = "unproven")] #[allow(deprecated)] impl OldInputPinConsumer where T: v1::InputPin @@ -264,14 +251,12 @@ mod tests { } } - #[cfg(feature = "unproven")] #[test] fn v1_v2_input_explicit() { let i = NewInputPinImpl{state: Ok(false)}; let _c: OldInputPinConsumer> = OldInputPinConsumer::new(i.into()); } - #[cfg(feature = "unproven")] #[test] fn v1_v2_input_state() { let i: OldInputPin<_> = NewInputPinImpl{state: Ok(false)}.into(); @@ -280,7 +265,6 @@ mod tests { assert_eq!(i.is_high(), false); } - #[cfg(feature = "unproven")] #[test] #[should_panic] fn v1_v2_input_panic() { diff --git a/src/digital/v2_compat.rs b/src/digital/v2_compat.rs index 4ae1da9a2..3ead76027 100644 --- a/src/digital/v2_compat.rs +++ b/src/digital/v2_compat.rs @@ -76,9 +76,6 @@ where impl v2::toggleable::Default for T where T: v1::toggleable::Default {} /// Implementation of fallible `v2::InputPin` for `v1::InputPin` digital traits -/// -/// Available behind `"unproven"` feature because `v1::InputPin` is -#[cfg(feature = "unproven")] #[allow(deprecated)] impl v2::InputPin for T where @@ -178,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 { @@ -195,12 +190,10 @@ mod tests { } } - #[cfg(feature = "unproven")] struct NewInputPinConsumer { _pin: T, } - #[cfg(feature = "unproven")] impl NewInputPinConsumer where T: v2::InputPin { pub fn new(pin: T) -> NewInputPinConsumer { @@ -208,14 +201,12 @@ mod tests { } } - #[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}; @@ -223,4 +214,4 @@ mod tests { assert_eq!(v2::InputPin::is_high(&mut i).unwrap(), false); assert_eq!(v2::InputPin::is_low(&mut i).unwrap(), true); } -} \ No newline at end of file +} From d9d1052c0967929b7185840a0f5585ce86780faa Mon Sep 17 00:00:00 2001 From: Nils VAN ZUIJLEN Date: Sun, 17 Nov 2019 21:28:57 +0100 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d7261970..fd5ff4893 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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