Skip to content

Instantly share code, notes, and snippets.

@nialv7
Created October 11, 2015 21:36
Show Gist options
  • Save nialv7/810b5817059ed107e63c to your computer and use it in GitHub Desktop.
Save nialv7/810b5817059ed107e63c to your computer and use it in GitHub Desktop.
Partial dynamic dispatch
trait Dump {
fn dump(&self);
}
struct A {
a: i32
}
impl Dump for A {
fn dump(&self) {
println!("{}", self.a);
}
}
fn dumpab<T: Dump+?Sized, S: Dump+?Sized>(a: &T, b: &S) {
a.dump();
b.dump();
}
fn main() {
let a = A {a: 1};
let b = A {a: 2};
dumpab(&a, &b as &Dump);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment