Struct duration_in_ms::DurationInms
source · pub struct DurationInms { /* private fields */ }
Expand description
Define a Duration in human readable form
Examples
let duration = DurationInms::try_from("80h").unwrap();
assert_eq!(format!("{:#}", duration), "3 day 8h".to_string());
assert_eq!(format!("{}", duration), "80h".to_string());
let duration = DurationInms::try_from("72h").unwrap();
assert_eq!(format!("{:#}", duration), "3 day".to_string());
assert_eq!(format!("{}", duration), "3 day".to_string());
let duration = DurationInms::try_from("18446744073709551615ns").unwrap();
assert_eq!(format!("{:#}", duration), "5 century 84 year 11 month 1 week 6 day 23h 34min 33s 709ms".to_string());
let duration = DurationInms::try_from("18446744073709551615ms").unwrap();
assert_eq!(format!("{:#}", duration), "5849424 century 17 year 4 month 1 week 2 day 14h 25min 51s 615ms".to_string());
// precision is ms
let duration = DurationInms::try_from("604800μs").unwrap();
assert_eq!(format!("{:#}", duration), "604ms".to_string());
assert_eq!(duration.to_string(), "604ms".to_string());
let duration = DurationInms::try_from("604800ms").unwrap();
assert_eq!(format!("{:#}", duration), "10min 4s 800ms".to_string());
assert_eq!(duration.to_string(), "604800ms".to_string());
let duration = DurationInms::try_from("604800s").unwrap();
assert_eq!(format!("{:#}", duration), "1 week".to_string());
let duration = DurationInms::try_from("604800s").unwrap();
assert_eq!(format!("{:#}", duration), "1 week".to_string(),"A");
assert_eq!(format!("{}", duration), "1 week".to_string(),"B");
let duration = DurationInms::try_from("608430s").unwrap();
assert_eq!(format!("{:#}", duration), "1 week 1h 30s".to_string());
assert_eq!(format!("{}", duration), "608430s".to_string(),"C");
Implementations§
source§impl DurationInms
impl DurationInms
pub const ONE_SECOND: Self = _
pub const ONE_MILLISECOND: Self = _
pub const fn new(ms: u64) -> Self
pub fn is_in(&self, range: &DurationInmsValidator) -> bool
Trait Implementations§
source§impl Add<Instant> for DurationInms
impl Add<Instant> for DurationInms
source§impl Clone for DurationInms
impl Clone for DurationInms
source§fn clone(&self) -> DurationInms
fn clone(&self) -> DurationInms
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Default for DurationInms
impl Default for DurationInms
source§impl Display for DurationInms
impl Display for DurationInms
source§impl From<&DurationInms> for Duration
impl From<&DurationInms> for Duration
source§fn from(duration: &DurationInms) -> Self
fn from(duration: &DurationInms) -> Self
Converts to this type from the input type.
source§impl From<&DurationInms> for u64
impl From<&DurationInms> for u64
source§fn from(duration: &DurationInms) -> Self
fn from(duration: &DurationInms) -> Self
Converts to this type from the input type.
source§impl From<DurationInms> for OsStr
impl From<DurationInms> for OsStr
source§fn from(duration: DurationInms) -> Self
fn from(duration: DurationInms) -> Self
Converts to this type from the input type.
source§impl From<u64> for DurationInms
impl From<u64> for DurationInms
source§impl Parse for DurationInms
impl Parse for DurationInms
fn parse(input: ParseStream<'_>) -> Result<Self>
source§impl PartialEq<DurationInms> for DurationInms
impl PartialEq<DurationInms> for DurationInms
source§fn eq(&self, other: &DurationInms) -> bool
fn eq(&self, other: &DurationInms) -> bool
source§impl PartialOrd<DurationInms> for DurationInms
impl PartialOrd<DurationInms> for DurationInms
source§fn partial_cmp(&self, other: &DurationInms) -> Option<Ordering>
fn partial_cmp(&self, other: &DurationInms) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl TryFrom<&str> for DurationInms
impl TryFrom<&str> for DurationInms
impl Copy for DurationInms
impl Eq for DurationInms
impl StructuralEq for DurationInms
impl StructuralPartialEq for DurationInms
Auto Trait Implementations§
impl RefUnwindSafe for DurationInms
impl Send for DurationInms
impl Sync for DurationInms
impl Unpin for DurationInms
impl UnwindSafe for DurationInms
Blanket Implementations§
source§impl<I> IntoResettable<OsStr> for Iwhere
I: Into<OsStr>,
impl<I> IntoResettable<OsStr> for Iwhere
I: Into<OsStr>,
source§fn into_resettable(self) -> Resettable<OsStr>
fn into_resettable(self) -> Resettable<OsStr>
Convert to the intended resettable type