Re:Rust for JavaScript Developers – Functions and Control Flow
by eximius on Monday July 06, 2020 @02:48AM
(#23745334)
Rust can also match on ranges which is perhaps the most idiomatic form for this.
[ Parent
| on HN ]
Re:Rust for JavaScript Developers – Functions and Control Flow
by delta1 on Monday July 06, 2020 @08:51AM
(#23747326)
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...
Re:Rust for JavaScript Developers – Functions and Control Flow
by nyanpasu64 on Monday July 06, 2020 @02:53PM
(#23751366)
This behaves differently for negative incomes, which are not prohibited by the i32 argument passed in (u32 cannot take on negative values).