Rust - Integers as indices, not values, should be of type `usize` by default
155

Source Post

One small suggestion from me:
if it is in Rust, for dedicated indices, not values, in the method signature, they are recommended to be of type usize, rather than i32, or other integer types.
Otherwise, there will be tedious conversions, which does not contain too much meaning, in my opinion :).
For example: the sum_region method.

    fn sum_region(&self, row1: i32, col1: i32, row2: i32, col2: i32) -> i32 {
        let row1: usize = row1 as usize;
        let row2: usize = row2 as usize;
        let col1: usize = col1 as usize;
        let col2: usize = col2 as usize;
        return  self.prefix_sums[row2 + 1][col2 + 1] -  self.prefix_sums[row2 + 1][col1] -  self.prefix_sums[row1][col2 + 1] +  self.prefix_sums[row1][col1];
    }

Thanks for this.

Comments (2)