Created
December 13, 2018 14:39
-
-
Save rust-play/c7870dc0780d04ec7c01a676af1cee61 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
/// 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