pub struct Duration { /* private fields */ }Expand description
Non-negative whole-second duration.
Implementations§
Source§impl Duration
impl Duration
Sourcepub fn from_seconds(s: f64) -> Self
pub fn from_seconds(s: f64) -> Self
Build from whole seconds (rounds up if fractional, clamps negatives / NaN to zero).
Sourcepub fn from_milliseconds(ms: f64) -> Self
pub fn from_milliseconds(ms: f64) -> Self
Build from milliseconds.
Sourcepub fn from_minutes(m: f64) -> Self
pub fn from_minutes(m: f64) -> Self
Build from minutes.
Sourcepub fn from_hours(h: f64) -> Self
pub fn from_hours(h: f64) -> Self
Build from hours.
Sourcepub fn from_weeks(w: f64) -> Self
pub fn from_weeks(w: f64) -> Self
Build from weeks.
Sourcepub fn from_months(m: f64) -> Self
pub fn from_months(m: f64) -> Self
Build from 30-day months.
Sourcepub fn from_years(y: f64) -> Self
pub fn from_years(y: f64) -> Self
Build from 365-day years.
Sourcepub fn from_std(d: Duration) -> Self
pub fn from_std(d: Duration) -> Self
Build from a std::time::Duration.
Sourcepub fn parse(s: &str) -> Result<Self, Error>
pub fn parse(s: &str) -> Result<Self, Error>
Parse strings like "1.5h", "5 d", "2weeks", "30s",
"1d 4h 5m 30s". Case-insensitive, whitespace-tolerant.
Supported unit families: ms / s / m / h / d / w /
month / y.
Sourcepub const fn to_seconds(self) -> i64
pub const fn to_seconds(self) -> i64
Whole-second count.
Sourcepub const fn to_milliseconds(self) -> i64
pub const fn to_milliseconds(self) -> i64
Milliseconds (whole-second precision).
Sourcepub fn to_minutes(self) -> f64
pub fn to_minutes(self) -> f64
Fractional minutes.
Sourcepub fn to_std(self) -> Duration
pub fn to_std(self) -> Duration
Convert to a std::time::Duration.
Trait Implementations§
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
impl Copy for Duration
impl Eq for Duration
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.