Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    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...


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: