Created
December 31, 2014 18:11
-
-
Save tilpner/c14b167b4b10bafbf782 to your computer and use it in GitHub Desktop.
matching.rs
This file contains 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
/// How can I elegantly make this work? | |
/// play.rust-lang.org didn't seem to be able to *share* right now, so I used gist... | |
#[allow(dead_code)] | |
trait D { | |
fn d(&mut self) {} | |
} | |
#[deriving(Show)] | |
struct A; | |
impl D for A {} | |
#[deriving(Show)] | |
struct B; | |
impl D for B {} | |
enum C { A(A), B(B), } | |
impl C { | |
fn foo(&mut self) { | |
match *self { | |
C::A(ref a) => a.d(), | |
C::B(ref b) => b.d() | |
} | |
} | |
} | |
fn main() {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment