pub struct Duration { /* private fields */ }Expand description
Signed duration, represented as seconds and normalized nanoseconds.
Implementations§
Source§impl Duration
impl Duration
pub const ZERO: Duration
Sourcepub fn new(seconds: i64, nanos: i32) -> Result<Duration, Error>
pub fn new(seconds: i64, nanos: i32) -> Result<Duration, Error>
Creates a duration from seconds and a nanosecond adjustment.
Sourcepub fn from_normalized(seconds: i64, nanos: u32) -> Result<Duration, Error>
pub fn from_normalized(seconds: i64, nanos: u32) -> Result<Duration, Error>
Creates a duration from normalized seconds and nanoseconds.
Sourcepub fn from_parts(seconds: i64, nanos: i64) -> Result<Duration, Error>
pub fn from_parts(seconds: i64, nanos: i64) -> Result<Duration, Error>
Creates a duration from seconds and an arbitrary nanosecond adjustment.
Sourcepub fn from_millis(millis: i64) -> Duration
pub fn from_millis(millis: i64) -> Duration
Creates a duration from milliseconds.
Sourcepub fn from_micros(micros: i64) -> Duration
pub fn from_micros(micros: i64) -> Duration
Creates a duration from microseconds.
Sourcepub const fn subsec_nanos(self) -> u32
pub const fn subsec_nanos(self) -> u32
Returns the normalized nanosecond component.
Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Returns whether this duration is greater than zero.
Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Returns whether this duration is less than zero.
Sourcepub fn to_millis(self) -> Result<i64, Error>
pub fn to_millis(self) -> Result<i64, Error>
Returns whole milliseconds, rounded down for sub-millisecond values.
Sourcepub fn to_micros(self) -> Result<i64, Error>
pub fn to_micros(self) -> Result<i64, Error>
Returns whole microseconds, rounded down for sub-microsecond values.
Sourcepub fn checked_sub(self, other: Duration) -> Result<Duration, Error>
pub fn checked_sub(self, other: Duration) -> Result<Duration, Error>
Subtracts other from this duration.
Sourcepub fn checked_neg(self) -> Result<Duration, Error>
pub fn checked_neg(self) -> Result<Duration, Error>
Negates this duration.
Trait Implementations§
impl Copy for Duration
impl Eq for Duration
Source§impl Ord for Duration
impl Ord for Duration
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for Duration
impl PartialOrd for Duration
Source§impl Serializer for Duration
impl Serializer for Duration
type Target = Duration
Source§fn write_data(
value: &Duration,
context: &mut WriteContext<'_>,
) -> Result<(), Error>
fn write_data( value: &Duration, context: &mut WriteContext<'_>, ) -> Result<(), Error>
Write the target body only.
Source§fn read_data(context: &mut ReadContext<'_>) -> Result<Duration, Error>
fn read_data(context: &mut ReadContext<'_>) -> Result<Duration, Error>
Read the target body only.
Source§fn default_value(_: &mut ReadContext<'_>) -> Result<Duration, Error>
fn default_value(_: &mut ReadContext<'_>) -> Result<Duration, Error>
Construct a target for a null or missing local value.
Source§fn read_arc_any(
context: &mut ReadContext<'_>,
) -> Result<Arc<dyn Any + Send + Sync>, Error>
fn read_arc_any( context: &mut ReadContext<'_>, ) -> Result<Arc<dyn Any + Send + Sync>, Error>
Read directly into the final owner for sync dynamic carriers.
impl StructuralPartialEq for Duration
Auto Trait Implementations§
impl Freeze for Duration
impl RefUnwindSafe for Duration
impl Send for Duration
impl Sync for Duration
impl Unpin for Duration
impl UnsafeUnpin for Duration
impl UnwindSafe for Duration
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more