ToU64

Trait ToU64 

Source
pub trait ToU64 {
    // Required method
    fn to_u64(self) -> u64;
}
Expand description

Trait for converting numeric-like values into a u64.

This is typically used to normalize custom duration types into milliseconds for compatibility with APIs like core::time::Duration::from_millis, which are commonly required in async sleep contexts.

§Safety and Behavior

For types that may exceed the u64 range (e.g., u128), values that cannot be losslessly converted will saturate to u64::MAX. This avoids propagating errors in time-sensitive code like ID generation. In such systems, a fallback to u64::MAX is generally safe: it typically causes a retry without compromising correctness, since most sane ID formats reserve no more than 48 bits for timestamps - far below the 64-bit boundary.

Required Methods§

Source

fn to_u64(self) -> u64

Implementations on Foreign Types§

Source§

impl ToU64 for u8

Source§

fn to_u64(self) -> u64

Source§

impl ToU64 for u16

Source§

fn to_u64(self) -> u64

Source§

impl ToU64 for u32

Source§

fn to_u64(self) -> u64

Source§

impl ToU64 for u64

Source§

fn to_u64(self) -> u64

Source§

impl ToU64 for u128

Source§

fn to_u64(self) -> u64

Implementors§