5 ms·
Rust can also match on ranges which is perhaps the most idiomatic form for this.
by eximius 6y ago
Rust can also match on ranges which is perhaps the most idiomatic form for this.
- delta1 6y agofn calculate_tax(income: i32) -> i32 { match income { 0..=9 => 0, 10..=49 => 20, _ => 50, } } https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=64cd9c40d4783dc95dbdb38ae2824c55 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- nyanpasu64 6y agoThis behaves differently for negative incomes, which are not prohibited by the i32 argument passed in (u32 cannot take on negative values).