News for hackers. Stuff that matters.
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.
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).
Re:Rust for JavaScript Developers – Functions and Control Flow by delta1 on Tuesday July 07, 2020 @04:09AM (#23756827)
Yeah I was just literally translating the previous code as an example, I didn't get the business rules specification

¯\_(ツ)_/¯

Re:Rust for JavaScript Developers – Functions and Control Flow by eximius on Monday July 06, 2020 @08:28PM (#23754351)
Ranges support negatives, so thats nice. Though i32::MIN..=9 is at least slightly odd.