Hacker News new | ask | show | jobs
by delta1 2180 days ago

    fn calculate_tax(income: i32) -> i32 {
        match income {
            0..=9 => 0,
            10..=49 => 20,
            _ => 50,
        }
    }
https://play.rust-lang.org/?version=stable&mode=debug&editio...
1 comments

This behaves differently for negative incomes, which are not prohibited by the i32 argument passed in (u32 cannot take on negative values).
Yeah I was just literally translating the previous code as an example, I didn't get the business rules specification

¯\_(ツ)_/¯

Ranges support negatives, so thats nice. Though i32::MIN..=9 is at least slightly odd.