pub trait WithPrecision: BitsPrecision {
// Required method
fn widen_to_precision(self, bits_precision: u32) -> Self;
// Provided methods
fn zero_with_precision(bits_precision: u32) -> Self
where Self: Zero { ... }
fn one_with_precision(bits_precision: u32) -> Self
where Self: One { ... }
fn widen_to_precision_of(self, witness: &Self) -> Self { ... }
fn zero_with_precision_of(witness: &Self) -> Self
where Self: Zero { ... }
fn one_with_precision_of(witness: &Self) -> Self
where Self: One { ... }
}Expand description
Establishes a value’s operating width from a witness — the constructive
companion to BitsPrecision. Method names mirror crypto-bigint’s
BoxedUint::{zero_with_precision, one_with_precision, widen}.
Why it exists: Zero::zero/One::one
are minimal-width on a runtime-width carrier, so a reducer seeded with zero()
and grown toward a modulus width operates at the seed width and wraps early —
correct on a fixed-width type, silently truncated on a variable-width one.
T::zero_with_precision_of(&m) seeds at the modulus width instead.
widen_to_precision grows, never shrinks, and
preserves the value (identity on a fixed-width carrier). It preserves value
only to a representation-compatible width — a fixed-point carrier’s fractional
format must match — which is why the _of forms take a witness value, not a
bit count. Those forms borrow the witness, so they carry no Copy bound and
serve Clone-only carriers, the case the family exists for.
use const_num_traits::WithPrecision;
// Fixed-width: width is the type; the requested precision is ignored.
assert_eq!(WithPrecision::widen_to_precision(5u32, 256), 5u32);
assert_eq!(WithPrecision::zero_with_precision_of(&99u32), 0u32);
let one: u32 = WithPrecision::one_with_precision(128);
assert_eq!(one, 1);Required Methods§
Sourcefn widen_to_precision(self, bits_precision: u32) -> Self
fn widen_to_precision(self, bits_precision: u32) -> Self
Returns self re-represented over a width of at least
bits_precision, preserving its numeric value. Never shrinks; on a
fixed-width carrier the width is the type and this is the identity.
Provided Methods§
Sourcefn zero_with_precision(bits_precision: u32) -> Selfwhere
Self: Zero,
fn zero_with_precision(bits_precision: u32) -> Selfwhere
Self: Zero,
A Zero carried at a width of at least bits_precision.
Sourcefn one_with_precision(bits_precision: u32) -> Selfwhere
Self: One,
fn one_with_precision(bits_precision: u32) -> Selfwhere
Self: One,
A One carried at a width of at least bits_precision.
Sourcefn widen_to_precision_of(self, witness: &Self) -> Self
fn widen_to_precision_of(self, witness: &Self) -> Self
widen_to_precision to the width of a
witness value — typically the modulus a reducer operates over. Prefer
this to hand-picking a bit count: the witness carries the intended width.
Sourcefn zero_with_precision_of(witness: &Self) -> Selfwhere
Self: Zero,
fn zero_with_precision_of(witness: &Self) -> Selfwhere
Self: Zero,
A Zero carried at the witness’s width — the width-safe
seed for a generic accumulator.
Sourcefn one_with_precision_of(witness: &Self) -> Selfwhere
Self: One,
fn one_with_precision_of(witness: &Self) -> Selfwhere
Self: One,
A One carried at the witness’s width.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".