templar_curator_primitives/utils/
mod.rs

1/// Convert seconds to nanoseconds, returning `None` on overflow.
2#[must_use]
3pub fn seconds_to_nanoseconds(seconds: u64) -> Option<u64> {
4    seconds.checked_mul(1_000_000_000)
5}
6
7/// Convert `u128` to `i128`, returning `None` when out of range.
8#[must_use]
9pub fn u128_to_i128_checked(value: u128) -> Option<i128> {
10    i128::try_from(value).ok()
11}
12
13/// Convert `i128` to `u128`, rejecting negative values.
14#[must_use]
15pub fn nonnegative_i128_to_u128(value: i128) -> Option<u128> {
16    u128::try_from(value).ok()
17}