pub struct SignedDuration { /* private fields */ }Expand description
Signed nanosecond-backed duration used for derived timing values.
This type preserves negative values that can arise after subtracting server
processing time or comparing wall-clock timestamps from different hosts. It
should not be used to represent raw elapsed wall-clock or monotonic time,
which is non-negative and represented by Duration.
§Example
Signed timing values retain a negative result instead of clamping clock skew or server processing adjustments to zero:
use irtt_client::SignedDuration;
let adjusted_rtt = SignedDuration::from_nanos(-250_000);
assert!(adjusted_rtt.is_negative());
assert_eq!(adjusted_rtt.as_micros(), -250);Implementations§
Source§impl SignedDuration
impl SignedDuration
Sourcepub const fn from_nanos(ns: i128) -> Self
pub const fn from_nanos(ns: i128) -> Self
Construct a signed duration from nanoseconds.
Sourcepub fn from_duration(duration: Duration) -> Self
pub fn from_duration(duration: Duration) -> Self
Convert a non-negative Duration into a signed duration.
Durations larger than i128::MAX nanoseconds saturate to i128::MAX.
Sourcepub const fn as_micros(self) -> i128
pub const fn as_micros(self) -> i128
Return the duration in whole microseconds, truncated toward zero.
Sourcepub const fn as_millis(self) -> i128
pub const fn as_millis(self) -> i128
Return the duration in whole milliseconds, truncated toward zero.
Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Return whether this duration is less than zero.