pub struct PrettyDuration {
text: String,
duration: Duration,
}Expand description
A duration parsed from a human-readable value.
Format: ( [NUMBER][UNIT] [SPACE]? )+
Unit:
- Seconds: s|sec|secs|seconds
- Minutes: m|min|mins|minutes
- Hours: h|hour|hours
- Days: d|day|days
Examples: 30s, 1m30s, 1m 30s, 2hours, 7d.
Resolution is one second; there are no sub-second units.
The spelling a value was parsed from is preserved, so a config that is read and written back keeps the author’s formatting. Values constructed in code are formatted with the largest units that divide them evenly.
Fields§
§text: StringThe text this value was parsed from, or the formatting of a value constructed in code. Always re-parses to the same duration.
duration: DurationImplementations§
Source§impl PrettyDuration
impl PrettyDuration
Sourcepub fn new(duration: Duration) -> Self
pub fn new(duration: Duration) -> Self
Sub-second precision is truncated, since no unit can express it and the spelling and the value would otherwise disagree.
pub fn as_duration(&self) -> Duration
pub fn from_secs(secs: u64) -> Self
Sourcepub fn from_mins(mins: u64) -> Self
pub fn from_mins(mins: u64) -> Self
Saturates at u64::MAX seconds, matching Self::from_hours and
Self::from_days. Parsing rejects that magnitude instead, because
there the amount comes from a config file rather than from a caller.
Sourcepub fn from_hours(hours: u64) -> Self
pub fn from_hours(hours: u64) -> Self
Saturates at u64::MAX seconds. See Self::from_mins.
Sourcepub fn from_days(days: u64) -> Self
pub fn from_days(days: u64) -> Self
Saturates at u64::MAX seconds. See Self::from_mins.
Trait Implementations§
Source§impl Clone for PrettyDuration
impl Clone for PrettyDuration
Source§fn clone(&self) -> PrettyDuration
fn clone(&self) -> PrettyDuration
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PrettyDuration
impl Debug for PrettyDuration
Source§impl Default for PrettyDuration
impl Default for PrettyDuration
Source§impl<'de> Deserialize<'de> for PrettyDuration
impl<'de> Deserialize<'de> for PrettyDuration
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for PrettyDuration
impl Display for PrettyDuration
Source§impl From<Duration> for PrettyDuration
impl From<Duration> for PrettyDuration
Source§impl From<PrettyDuration> for Duration
impl From<PrettyDuration> for Duration
Source§fn from(duration: PrettyDuration) -> Self
fn from(duration: PrettyDuration) -> Self
Source§impl FromStr for PrettyDuration
impl FromStr for PrettyDuration
Source§impl Hash for PrettyDuration
impl Hash for PrettyDuration
Source§impl JsonSchema for PrettyDuration
impl JsonSchema for PrettyDuration
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl Ord for PrettyDuration
impl Ord for PrettyDuration
Source§impl PartialEq for PrettyDuration
impl PartialEq for PrettyDuration
Source§impl PartialOrd for PrettyDuration
impl PartialOrd for PrettyDuration
Source§impl Serialize for PrettyDuration
impl Serialize for PrettyDuration
impl Eq for PrettyDuration
Auto Trait Implementations§
impl Freeze for PrettyDuration
impl RefUnwindSafe for PrettyDuration
impl Send for PrettyDuration
impl Sync for PrettyDuration
impl Unpin for PrettyDuration
impl UnsafeUnpin for PrettyDuration
impl UnwindSafe for PrettyDuration
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.