Guest User

Untitled

a guest
Nov 13th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. enum SoI {
  2. S(String),
  3. I(i32),
  4. }
  5.  
  6. fn main() {
  7.  
  8. let s = SoI::S(String::from("one"));
  9.  
  10.  
  11. // why this ?
  12.  
  13. match s {
  14. SoI::S(ref x) if x == "one" => { println!("one") },
  15. _ => println!("not one"),
  16. }
  17.  
  18.  
  19. // if it can be done like this?
  20.  
  21. match s {
  22. SoI::S(x) => if x == "one" { println!("one"); },
  23. _ => println!("not one"),
  24. }
  25. }
  26.  
  27.  
  28.  
  29.  
  30.  
  31. // which is more preferable??
Add Comment
Please, Sign In to add comment