pub trait BitsPrecision: Sized {
// Required method
fn bits_precision(&self) -> u32;
}Expand description
A value’s operating width in bits — how many bits it is represented over,
possibly less than its storage capacity. Fixed per type for a fixed-width
carrier (u32 → 32, arbitrary-int’s u48 → 48), per-value for a
variable-width bignum. Named after crypto-bigint’s BoxedUint::bits_precision.
Contrast BitWidth::bit_width (bit-length — significant bits,
<= bits_precision()).
Binary carriers only — not decimals/floats/rationals (non-binary precision).
Footgun: on a variable-width carrier the identity is minimal-width, so
bits_precision(&Zero::zero()) is 0, not the operating width — probe a
full-width witness (the modulus), never the identity. See WithPrecision.
&self, not self: a width query never consumes its value (cf.
FromBytes), and borrowing lets a non-Copy carrier be a
witness without a clone — how WithPrecision’s _of forms stay Copy-free.
Required Methods§
Sourcefn bits_precision(&self) -> u32
fn bits_precision(&self) -> u32
The number of bits self operates over (its constructed width).
use const_num_traits::BitsPrecision;
assert_eq!(BitsPrecision::bits_precision(&0u32), 32);
assert_eq!(BitsPrecision::bits_precision(&u32::MAX), 32);
assert_eq!(BitsPrecision::bits_precision(&7u8), 8);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".