Skip to content

Instantly share code, notes, and snippets.

@XMPPwocky
Created November 10, 2014 03:51
Show Gist options
  • Save XMPPwocky/ee8fb2a4c7a253bbf968 to your computer and use it in GitHub Desktop.
Save XMPPwocky/ee8fb2a4c7a253bbf968 to your computer and use it in GitHub Desktop.
struct Base<T: Derived> {
x: u32,
derived: T
}
trait Derived {
fn foo_the_bars(&mut self, base: &mut Base) -> u32;
}
struct SomeDerived {
y: u32
}
impl Derived for SomeDerived {
fn foo_the_bars(&mut self, base: &mut Base) -> u32 {
self.y += 1;
base.x + self.y
}
}
impl Derived for Box<Derived> {
fn foo_the_bars(&mut self, base: &mut Base) -> u32 {
**self.foo_the_bars(base)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment