Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// 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),
- }
- }
- }
Add Comment
Please, Sign In to add comment