From c91e84ee5c1d0363dfe685e7b8f8359d1ab39ec4 Mon Sep 17 00:00:00 2001 From: Roma Sokolov Date: Sun, 12 May 2019 19:15:12 +0200 Subject: [PATCH] Provide v2_compat for ToggleableOutputPin fixes #137 --- src/digital/v2_compat.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/digital/v2_compat.rs b/src/digital/v2_compat.rs index 779c089d3..bb5bae8b5 100644 --- a/src/digital/v2_compat.rs +++ b/src/digital/v2_compat.rs @@ -39,6 +39,9 @@ where } } +#[cfg(feature = "unproven")] +#[allow(deprecated)] +impl v2::toggleable::Default for T where T: v1::toggleable::Default {} /// Implementation of fallible `v2::InputPin` for `v1::InputPin` digital traits #[cfg(feature = "unproven")] @@ -81,6 +84,20 @@ mod tests { } } + #[allow(deprecated)] + impl v1::StatefulOutputPin for OldOutputPinImpl { + fn is_set_low(&self) -> bool { + self.state == false + } + + fn is_set_high(&self) -> bool { + self.state == true + } + } + + #[allow(deprecated)] + impl v1::toggleable::Default for OldOutputPinImpl {} + struct NewOutputPinConsumer { _pin: T, } @@ -92,6 +109,25 @@ mod tests { } } + struct NewToggleablePinConsumer { + _pin: T, + } + + impl NewToggleablePinConsumer + where + T: v2::ToggleableOutputPin, + { + pub fn new(pin: T) -> NewToggleablePinConsumer { + NewToggleablePinConsumer { _pin: pin } + } + } + + #[test] + fn v2_v1_toggleable_implicit() { + let i = OldOutputPinImpl { state: false }; + let _c = NewToggleablePinConsumer::new(i); + } + #[test] fn v2_v1_output_implicit() { let i = OldOutputPinImpl{state: false};