Guest User

Untitled

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