Skip to content

Commit

Permalink
Merge #138
Browse files Browse the repository at this point in the history
138: Provide v2_compat for ToggleableOutputPin r=ryankurte a=little-arhat

fixes #137

Co-authored-by: Roma Sokolov <[email protected]>
  • Loading branch information
bors[bot] and little-arhat committed May 14, 2019
2 parents 9e6ab5a + c91e84e commit b2bbae4
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/digital/v2_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ where
}
}

#[cfg(feature = "unproven")]
#[allow(deprecated)]
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")]
Expand Down Expand Up @@ -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<T: v2::OutputPin> {
_pin: T,
}
Expand All @@ -92,6 +109,25 @@ mod tests {
}
}

struct NewToggleablePinConsumer<T: v2::ToggleableOutputPin> {
_pin: T,
}

impl<T> NewToggleablePinConsumer<T>
where
T: v2::ToggleableOutputPin,
{
pub fn new(pin: T) -> NewToggleablePinConsumer<T> {
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};
Expand Down

0 comments on commit b2bbae4

Please sign in to comment.