Created
April 19, 2020 03:40
-
-
Save tstellanova/8e98faa593d939b5bae9ea9fe6a0bff9 to your computer and use it in GitHub Desktop.
Implement a newtype that wraps an existing type and implements a public trait
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub struct ToggleThing<T> { | |
| inner: T | |
| } | |
| impl<T> StatefulOutputPin for ToggleThing<T> | |
| where T: StatefulOutputPin + OutputPin | |
| { | |
| fn is_set_high(&self) -> Result<bool, Self::Error> { | |
| self.inner.is_set_high() | |
| } | |
| fn is_set_low(&self) -> Result<bool, Self::Error> { | |
| self.inner.is_set_low() | |
| } | |
| } | |
| impl<T> OutputPin for ToggleThing<T> | |
| where T: StatefulOutputPin + OutputPin | |
| { | |
| type Error = T::Error; | |
| fn set_low(&mut self) -> Result<(), Self::Error> { | |
| self.inner.set_low() | |
| } | |
| fn set_high(&mut self) -> Result<(), Self::Error> { | |
| self.inner.set_high() | |
| } | |
| } | |
| impl<T> toggleable::Default for ToggleThing<T> | |
| where T: StatefulOutputPin + OutputPin | |
| { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment