pub struct PositiveDuration(/* private fields */);Expand description
A duration is a unit of time that represents the amount of time required to complete a task.
Implementations§
Source§impl PositiveDuration
impl PositiveDuration
Sourcepub fn parse_from_str(s: &str) -> Result<Self, DurationError>
pub fn parse_from_str(s: &str) -> Result<Self, DurationError>
Tries to parse a string and return the corresponding [PositiveDuration]
§Arguments
s- The string to parse. Currently, only hours are supported in the format “X h”.
§Returns
Ok(PositiveDuration)- If the input string could be parsed into aPositiveDuration.Err(DurationError)- If the input string couldn’t be parsed into aPositiveDuration.
§Errors
DurationError::InvalidInput- If the input string couldn’t be parsed into aPositiveDuration.DurationError::ExceedsMaximumDuration- If the parsed duration exceeds the maximum allowed value.
§Panics
This function uses expect, but it should only panic in case of a bug.
§Examples
use planter_core::duration::PositiveDuration;
let duration = PositiveDuration::parse_from_str("8 h").unwrap();
assert_eq!(duration.num_hours(), 8);ⓘ
use planter_core::duration::PositiveDuration;
/// Passing invalid input will result in an `[DurationError::InvalidInput]`
let duration = PositiveDuration::parse_from_str("random garbage").unwrap();Trait Implementations§
Source§impl Clone for PositiveDuration
impl Clone for PositiveDuration
Source§fn clone(&self) -> PositiveDuration
fn clone(&self) -> PositiveDuration
Returns a duplicate 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 Debug for PositiveDuration
impl Debug for PositiveDuration
Source§impl Default for PositiveDuration
impl Default for PositiveDuration
Source§fn default() -> PositiveDuration
fn default() -> PositiveDuration
Returns the “default value” for a type. Read more
Source§impl Deref for PositiveDuration
impl Deref for PositiveDuration
Source§impl Ord for PositiveDuration
impl Ord for PositiveDuration
Source§fn cmp(&self, other: &PositiveDuration) -> Ordering
fn cmp(&self, other: &PositiveDuration) -> Ordering
1.21.0 · 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 PartialEq for PositiveDuration
impl PartialEq for PositiveDuration
Source§impl PartialOrd for PositiveDuration
impl PartialOrd for PositiveDuration
Source§impl TryFrom<TimeDelta> for PositiveDuration
impl TryFrom<TimeDelta> for PositiveDuration
impl Copy for PositiveDuration
impl Eq for PositiveDuration
impl StructuralPartialEq for PositiveDuration
Auto Trait Implementations§
impl Freeze for PositiveDuration
impl RefUnwindSafe for PositiveDuration
impl Send for PositiveDuration
impl Sync for PositiveDuration
impl Unpin for PositiveDuration
impl UnwindSafe for PositiveDuration
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<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
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more