Skip to content

Instantly share code, notes, and snippets.

@tstellanova
Created April 19, 2020 03:40
Show Gist options
  • Save tstellanova/8e98faa593d939b5bae9ea9fe6a0bff9 to your computer and use it in GitHub Desktop.
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
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