Advertisement
Guest User

Untitled

a guest
Oct 10th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. enum E {
  2. A,
  3. B,
  4. C,
  5. D(i32),
  6. }
  7.  
  8. impl E {
  9. fn is_unit_type(&self) -> bool {
  10. match self {
  11. E::A | E::B | E::C => true,
  12. _ => false
  13. }
  14. }
  15. }
  16.  
  17. fn main() {
  18. match &E::A {
  19. E::D(i) => println!("{}", i),
  20. other if other.is_unit_type() => println!("unit type"),
  21. // is there a way to let the compiler know there are no more possible matches?
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement