Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn test_return_shortcircuit(a: i32) -> i32 {
- match a > 0 {
- true => (),
- false => return -1,
- }
- // random other bindings just for parity
- let b = a * 3;
- let c = b * 2;
- c * b
- }
- fn test_error_case(a: i32) -> i32 {
- match a > 0 {
- true => -1,
- false => 1,
- }
- //uncomment below to see error.
- //let b = a * 2;
- //b
- }
- fn test_empty_shortcircuit(a: i32) {
- match a > 0 {
- true => (),
- false => return,
- }
- println!("a = {}", a);
- println!("After match block!");
- }
- fn main() {
- println!("res: {}", test_return_shortcircuit(-20));
- println!("res2: {}", test_return_shortcircuit(20));
- test_empty_shortcircuit(-1);
- test_empty_shortcircuit(1);
- test_error_case(1);
- }
Add Comment
Please, Sign In to add comment