5 ms·
Just curious. Is this the normal way: let recursion_available = (0b1000_0000 & r_z_ad_cd_rcod) == 0b1000_0000 That just seems redundant. If you declared t
by DigitalJack 10y ago
Just curious. Is this the normal way:
let recursion_available = (0b1000_0000 & r_z_ad_cd_rcod) == 0b1000_0000
That just seems redundant. If you declared the var as a Boolean, would the == 0bxxxx part have been necessary?
- chrismorgan 10y agoIf r_z_ad_cd_rcod is of type u8, then 0b1000_0000 & r_z_ad_cd_rcod is also of type u8, containing the value 0 or 128. It is (by design) not possible to simply cast a number to a bool in Rust; comparing it with some value is the way you are required to do this. You can do this with `== 0b1000_0000` if you want, or `!= 0` would do just as well. Rust is deliberately explicit about conversions between types; it’s less error-prone, though often more verbose. It’s a part of the language’s philosophy.
- cpeterso 10y agoThis seems like a good use case for a bit mask query function. I see Rust has a bitflags crate: https://doc.rust-lang.org/bitflags/bitflags/index.html https://doc.rust-lang.org/bitflags/bitflags/index.html
- bluejekyll 10y agoI found that after I had already written a lot of that code. I haven't had much reason to go back and change it, but any PR's if someone wants to do it, would be accepted.
- deleted 10y ago[deleted]
- vog 10y agoWhat about simply replacing all "== 0b..." with "!= 0"? That would already be a good improvement, both in terms of DRY and readability, without the need of adding another dependency.
- deleted 10y ago[deleted]
- Matthias247 10y agoIt could be replaced with != 0. But an implicit conversion from integer to boolean like in C is not possible.
- deleted 10y ago[deleted]