Closed tcharding closed 1 month ago
Using From (or into()) is easier to read than using casts because it stops devs having to wonder if an data being lost.
From
into()
We have a few places where we use casts to cast u8 to usize
u8
usize
let log1 = LOG[self.0 as usize]; let log2 = LOG[other.0 as usize];
Could be written as:
let log1 = LOG[usize::from(self.0)]; let log2 = LOG[usize::from(other.0)];
Interesting. TIL that usize implements From<u8> and From<u16>. (But not From from any other numeric type, and I don't believe Into for any numeric types).
From<u8>
From<u16>
Into
Using
From
(orinto()
) is easier to read than using casts because it stops devs having to wonder if an data being lost.We have a few places where we use casts to cast
u8
tousize
Could be written as: