SHARE
TWEET

Untitled

a guest Oct 10th, 2019 117 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top