pub struct UpDuration(/* private fields */);Expand description
A duration from the Flockfile grammar ^\d+(ms|h|m|s)?$
Plain digits are milliseconds; ms/s/m/h are
milliseconds/seconds/minutes/hours. Used for min_uptime,
kill_timeout, and the other lifecycle timers.
ms is checked before the single-letter suffixes, so m still means
minutes and only a trailing ms means milliseconds: 5m and 5ms
differ by a factor of sixty thousand.
§Example
use shep_core::values::UpDuration;
assert_eq!("30s".parse::<UpDuration>()?.as_millis(), 30_000);
assert_eq!("500ms".parse::<UpDuration>()?.as_millis(), 500);
assert_eq!("5m".parse::<UpDuration>()?.as_millis(), 300_000);
assert!("30S".parse::<UpDuration>().is_err()); // lowercase units onlyImplementations§
Source§impl UpDuration
impl UpDuration
Sourcepub const fn from_millis(ms: u64) -> Self
pub const fn from_millis(ms: u64) -> Self
Wraps a raw millisecond count
Sourcepub const fn as_duration(self) -> Duration
pub const fn as_duration(self) -> Duration
Returns the wrapped core::time::Duration
Trait Implementations§
Source§impl Clone for UpDuration
impl Clone for UpDuration
Source§fn clone(&self) -> UpDuration
fn clone(&self) -> UpDuration
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for UpDuration
Source§impl Debug for UpDuration
impl Debug for UpDuration
Source§impl<'de> Deserialize<'de> for UpDuration
impl<'de> Deserialize<'de> for UpDuration
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl Display for UpDuration
Formats with the largest unit dividing the value exactly (ms as digits)
impl Display for UpDuration
Formats with the largest unit dividing the value exactly (ms as digits)
impl Eq for UpDuration
Source§impl FromStr for UpDuration
impl FromStr for UpDuration
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parses ^\d+(ms|h|m|s)?$: plain digits are milliseconds
ms is matched before the single-letter suffixes below, so a
trailing m alone still means minutes.
§Errors
ParseUpDurationError::Empty: empty input.ParseUpDurationError::MissingDigits: unit with no digits.ParseUpDurationError::InvalidCharacter: anything outside ASCII digits plus one trailing lowercaseh/m/s/ms.ParseUpDurationError::Overflow: milliseconds overflowu64.
Source§type Err = ParseUpDurationError
type Err = ParseUpDurationError
Source§impl Hash for UpDuration
impl Hash for UpDuration
Source§impl JsonSchema for UpDuration
Available on crate feature schema only.String-shaped, matching this type’s Serialize/Deserialize: see
MemSize’s own JsonSchema impl for the full reasoning, which applies
here unchanged.
impl JsonSchema for UpDuration
schema only.String-shaped, matching this type’s Serialize/Deserialize: see
MemSize’s own JsonSchema impl for the full reasoning, which applies
here unchanged.
Source§fn json_schema(_: &mut SchemaGenerator) -> Schema
fn json_schema(_: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl Ord for UpDuration
impl Ord for UpDuration
Source§fn cmp(&self, other: &UpDuration) -> Ordering
fn cmp(&self, other: &UpDuration) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for UpDuration
impl PartialEq for UpDuration
Source§impl PartialOrd for UpDuration
impl PartialOrd for UpDuration
Source§impl Serialize for UpDuration
impl Serialize for UpDuration
impl StructuralPartialEq for UpDuration
Auto Trait Implementations§
impl Freeze for UpDuration
impl RefUnwindSafe for UpDuration
impl Send for UpDuration
impl Sync for UpDuration
impl Unpin for UpDuration
impl UnsafeUnpin for UpDuration
impl UnwindSafe for UpDuration
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,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.