Created
October 11, 2015 21:36
-
-
Save nialv7/810b5817059ed107e63c to your computer and use it in GitHub Desktop.
Partial dynamic dispatch
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
| 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