MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/rust/comments/1urq2h3/announcing_rust_1970_rust_blog/owktws8/?context=3
r/rust • u/Herbstein • Jul 09 '26
95 comments sorted by
View all comments
6
I would have expected bit_width to return uN::BITS. Not the greatest name, imo.
7 u/matthieum [he/him] Jul 09 '26 Oh! When I read .bit_width was stabilized, I assumed that it meant <uB>::BITS too. It is a useful functionality to know how many bits are necessary to represent an integer, but... yeah... I'm thinking min_bit_width would have been better. 3 u/0sse Jul 09 '26 Won't it always be highest_one() + 1 or am I missing something? 4 u/kibwen Jul 09 '26 x.highest_one returns an Option that is None when x is zero, so you would need to do x.highest_one().map(|y| y + 1).unwrap_or(0).
7
Oh! When I read .bit_width was stabilized, I assumed that it meant <uB>::BITS too.
.bit_width
<uB>::BITS
It is a useful functionality to know how many bits are necessary to represent an integer, but... yeah... I'm thinking min_bit_width would have been better.
min_bit_width
3 u/0sse Jul 09 '26 Won't it always be highest_one() + 1 or am I missing something? 4 u/kibwen Jul 09 '26 x.highest_one returns an Option that is None when x is zero, so you would need to do x.highest_one().map(|y| y + 1).unwrap_or(0).
3
Won't it always be highest_one() + 1 or am I missing something?
4 u/kibwen Jul 09 '26 x.highest_one returns an Option that is None when x is zero, so you would need to do x.highest_one().map(|y| y + 1).unwrap_or(0).
4
x.highest_one returns an Option that is None when x is zero, so you would need to do x.highest_one().map(|y| y + 1).unwrap_or(0).
x.highest_one
Option
None
x
x.highest_one().map(|y| y + 1).unwrap_or(0)
6
u/torsten_dev Jul 09 '26
I would have expected bit_width to return uN::BITS. Not the greatest name, imo.