Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created August 22, 2019 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/0369b0abc6a48c0da86175cb56451178 to your computer and use it in GitHub Desktop.
Save rust-play/0369b0abc6a48c0da86175cb56451178 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#[derive(Debug, Clone, Copy)]
enum Foo {
A,
B,
C
}
fn main() {
let x = Foo::A;
match x {
Foo::A => println!("A"),
_ => println!("not A"),
}
match x {
A => println!("this is just a variable called 'A', {:?}", A),
Asdf => println!("also just a variable, but the 'A' branch will match before this"),
}
{
use Foo::*;
match x {
B => println!("the enum variants are in scope here"),
A => println!("so this second arm will match"),
C => println!("C")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment