Guest User

Untitled

a guest
May 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. fn test_return_shortcircuit(a: i32) -> i32 {
  2. match a > 0 {
  3. true => (),
  4. false => return -1,
  5. }
  6.  
  7. // random other bindings just for parity
  8. let b = a * 3;
  9. let c = b * 2;
  10. c * b
  11. }
  12.  
  13. fn test_error_case(a: i32) -> i32 {
  14. match a > 0 {
  15. true => -1,
  16. false => 1,
  17. }
  18.  
  19. //uncomment below to see error.
  20. //let b = a * 2;
  21. //b
  22. }
  23.  
  24. fn test_empty_shortcircuit(a: i32) {
  25. match a > 0 {
  26. true => (),
  27. false => return,
  28. }
  29.  
  30. println!("a = {}", a);
  31. println!("After match block!");
  32. }
  33.  
  34. fn main() {
  35. println!("res: {}", test_return_shortcircuit(-20));
  36. println!("res2: {}", test_return_shortcircuit(20));
  37.  
  38. test_empty_shortcircuit(-1);
  39. test_empty_shortcircuit(1);
  40.  
  41. test_error_case(1);
  42. }
Add Comment
Please, Sign In to add comment