Skip to main content

Module numbers

Module numbers 

Source
Expand description

Checked numeric conversion helpers.

Service code often crosses database, filesystem, and API boundaries that use different integer widths and signedness. These helpers make overflow and sign-loss checks explicit while producing consistent error messages for callers.

Functionsยง

bytes_to_usize
Converts a signed byte count to usize.
calc_total_chunks
Calculates the number of chunks needed to cover total_size.
f64_seconds_to_u64_millis
Converts seconds represented as f64 to rounded milliseconds.
i32_to_usize
Converts i32 to usize.
i64_to_i32
Converts i64 to i32.
i64_to_u64
Converts i64 to u64.
i64_to_usize
Converts i64 to usize.
non_zero_u32
Converts 0 to NonZeroU32::MIN and preserves non-zero values.
non_zero_u64
Converts 0 to NonZeroU64::MIN and preserves non-zero values.
u32_to_i32
Converts u32 to i32.
u32_to_i64
Converts u32 to i64.
u32_to_usize
Converts u32 to usize.
u64_to_i64
Converts u64 to i64.
u64_to_usize
Converts u64 to usize.
u128_to_u64
Converts u128 to u64.
u128_to_u64_saturating
Converts u128 to u64, saturating values above u64::MAX.
usize_to_i32
Converts usize to i32.
usize_to_i64
Converts usize values such as Vec::len() or byte-slice lengths to i64.
usize_to_u32
Converts usize to u32.
usize_to_u64
Converts usize to u64.