pub const fn decode_option_duration(encoded: u128) -> Option<Duration>Expand description
Decode an Option<Duration> from an encoded u128.
Accepts non-canonical input without panicking. The Some(_)
encoding stores 64 bits of seconds in bits 32..=95 and up to 30
bits of nanoseconds in bits 0..=31 (bit 127 is the Some/None
discriminant, bits 96..=126 are unused). If the decoded nanosecond
count is 10⁹ or more — which encode_option_duration never
produces, but which can appear when the encoded value comes from
corrupted storage or untrusted input — the extra whole seconds are
folded into the seconds field; if that push past u64::MAX, the
result saturates at Duration::MAX.
This means decode_option_duration(u128::MAX) yields
Some(Duration::MAX) rather than panicking as the previous
implementation did.