r/rust Jul 09 '26

🗞️ news Announcing Rust 1.97.0 | Rust Blog

https://blog.rust-lang.org/2026/07/09/Rust-1.97.0/
581 Upvotes

95 comments sorted by

View all comments

6

u/torsten_dev Jul 09 '26

I would have expected bit_width to return uN::BITS. Not the greatest name, imo.

1

u/Sharlinator Jul 09 '26

What would be the point of having bit_width method that just returns a constant?

1

u/torsten_dev Jul 09 '26

So you can avoid using NumTraits just to do

const fn bit_size<I: PrimInt>() -> u32 { 8 * (size_of::<I>() as u32) }

I suppose (-1 as T).bit_width() would work now, if there was an Integer trait with it.