Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #![feature(slice_patterns)]
  2.  
  3. #[derive(Debug,PartialEq)]
  4. enum Errors {
  5. Exploded,
  6. Imploded,
  7. }
  8.  
  9. impl Errors {
  10. fn to_u32(self) -> u32 {
  11. self as u32
  12. }
  13. }
  14.  
  15. fn main() {
  16. let errors = [Errors::Exploded, Errors::Imploded];
  17.  
  18. // let msg = match &errors[..] {
  19. // [Errors::Exploded, Errors::Imploded] => "It exploded and then imploded",
  20. // _ => "Not sure what happened",
  21. // };
  22.  
  23. let errors = [Errors::Exploded.to_u32(), Errors::Imploded.to_u32()];
  24.  
  25. let msg = match &errors[..] {
  26. [Errors::Exploded.to_u32(), Errors::Imploded.to_u32()] => "It exploded and then imploded",
  27. _ => "Not sure what happened",
  28. };
  29.  
  30. println!("{:?}", errors)
  31. println!("{:?}", msg)
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement