Guest User

Untitled

a guest
Dec 13th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. /// Enum the great!
  2.  
  3. #[derive(Debug)]
  4. enum DeviceKind {
  5. USB { vid: u16, pid: u16 },
  6. Serial { port: String },
  7. }
  8.  
  9. fn main() {
  10. let devices = [
  11. DeviceKind::USB {
  12. vid: 0x8006,
  13. pid: 1234,
  14. },
  15. DeviceKind::Serial {
  16. port: String::from("COM1"),
  17. },
  18. ]; // I love it!
  19.  
  20. println!("devices: {:#?}", devices);
  21.  
  22. for x in &devices {
  23. match x {
  24. DeviceKind::USB { vid, pid } => println!("vid: {}, pid: {}", vid, pid),
  25. DeviceKind::Serial { port } => println!("Port: {}", port),
  26. }
  27. }
  28. }
Add Comment
Please, Sign In to add comment