Skip to content

Instantly share code, notes, and snippets.

@vijairaj
Forked from rust-play/playground.rs
Created December 13, 2018 14:40
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 vijairaj/41744b56c884b23afe0fc2a2e6e87f79 to your computer and use it in GitHub Desktop.
Save vijairaj/41744b56c884b23afe0fc2a2e6e87f79 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
/// Enum the great!
#[derive(Debug)]
enum DeviceKind {
USB { vid: u16, pid: u16 },
Serial { port: String },
}
fn main() {
let devices = [
DeviceKind::USB {
vid: 0x8006,
pid: 1234,
},
DeviceKind::Serial {
port: String::from("COM1"),
},
]; // I love it!
println!("devices: {:#?}", devices);
for x in &devices {
match x {
DeviceKind::USB { vid, pid } => println!("vid: {}, pid: {}", vid, pid),
DeviceKind::Serial { port } => println!("Port: {}", port),
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment