How to get the length of `usize`

the length of usize depends on the arch, such as 64bit or 32bit. So How can I get it

std::mem::size_of::<usize>()

7 Likes

There's also a compile-time check:

#[cfg(target_pointer_width = "64")]
8 Likes

What about usize::BITS :thinking:

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.