Skip to main content

Module math

Module math 

Source
Expand description

Arithmetic checking and numeric conversion helpers.

Exported macros separate recoverable, expected, and prevalidated arithmetic. Conversion helpers centralize errors, panics, and deliberate truncation.

Modulesยง

expect_into ๐Ÿ”’
expected ๐Ÿ”’
tried ๐Ÿ”’

Macrosยง

checked_ops
Transforms arithmetic expressions into checked operations.

Constantsยง

USIZE_MAX_EXCLUSIVE ๐Ÿ”’

Traitsยง

ExpectInto
Converts values with TryFrom and panics on failure.
Expected
Adds checked arithmetic methods that panic on failure.
Tried
Adds checked arithmetic methods that return a Result.

Functionsยง

effective_cap
Combines per-call and configuration concurrency caps.
expect_into
Converts a value with TryFrom and panics if conversion fails.
fetch_add_usize
Adds a usize count to an atomic u64 counter, saturating the count at u64::MAX.
ruma_from_u64
Converts a u64 to a Matrix unsigned integer.
ruma_from_usize
Converts a usize to a Matrix unsigned integer.
ruma_from_usize_saturating
Converts a usize to a Matrix unsigned integer, saturating at the largest value [UInt] supports.
try_into
Converts a value with TryFrom and maps failure to an arithmetic error.
u64_from_u128_saturating
Converts a u128 to u64, saturating at u64::MAX.
u64_from_usize_saturating
Converts a usize to u64, saturating at u64::MAX.
usize_from_f64
Converts a representable nonnegative f64 to usize by truncating toward zero.
usize_from_ruma
Converts a Matrix unsigned integer to usize.
usize_from_ruma_bounded
Converts a Matrix unsigned integer to a bounded usize.
usize_from_u64_truncated
Converts a u64 to usize with deliberate truncation when necessary.