HumanReadableDuration

Struct HumanReadableDuration 

Source
pub struct HumanReadableDuration { /* private fields */ }
Expand description

A data structure for parsing and managing a human readable duration representation

Trait Implementations§

Source§

impl AsDays for HumanReadableDuration

Source§

fn as_days(&self) -> u64

Get the duration time in full days

§Example
use std::str::FromStr;
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::AsDays;

let duration = HumanReadableDuration::from_str("48h");

assert_eq!(2, duration.unwrap().as_days());
Source§

impl AsDuration for HumanReadableDuration

Source§

fn as_duration(&self) -> Duration

Convert the object to a chrono::Duration representation.

§Example
use std::str::FromStr;
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::AsDuration;

let duration = HumanReadableDuration::from_str("65m").unwrap();

assert_eq!(3900, duration.as_duration().num_seconds());
assert_eq!(1, duration.as_duration().num_hours());
Source§

impl AsHours for HumanReadableDuration

Source§

fn as_hours(&self) -> u64

Get the duration time in full hours

§Example
use std::str::FromStr;
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::AsHours;

let duration = HumanReadableDuration::from_str("65m");

assert_eq!(1, duration.unwrap().as_hours());
Source§

impl AsMinutes for HumanReadableDuration

Source§

fn as_minutes(&self) -> u64

Get the duration time in full minutes

§Example
use std::str::FromStr;
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::AsMinutes;

let duration = HumanReadableDuration::from_str("65s");

assert_eq!(1, duration.unwrap().as_minutes());
Source§

impl AsSeconds for HumanReadableDuration

Source§

fn as_seconds(&self) -> u64

Get the duration time in seconds

§Example
use std::str::FromStr;
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::AsSeconds;

let duration = HumanReadableDuration::from_str("10s");

assert_eq!(10, duration.unwrap().as_seconds());
Source§

impl From<u16> for HumanReadableDuration

Used to do value-to-value conversions while consuming the input value. It is the reciprocal of Into.

Source§

fn from(value: u16) -> Self

Create an instance for HumanReadableDuration from a u16 field representing the seconds

§Example
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::{AsMinutes, AsSeconds};

let seconds: u16 = 300;
let representation = HumanReadableDuration::from(seconds);

assert_eq!(300, representation.as_seconds());
assert_eq!(5, representation.as_minutes());
Source§

impl From<u32> for HumanReadableDuration

Used to do value-to-value conversions while consuming the input value. It is the reciprocal of Into.

Source§

fn from(value: u32) -> Self

Create an instance for HumanReadableDuration from a u32 field representing the seconds

§Example
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::{AsMinutes, AsSeconds};

let seconds: u32 = 300;
let representation = HumanReadableDuration::from(seconds);

assert_eq!(300, representation.as_seconds());
assert_eq!(5, representation.as_minutes());
Source§

impl From<u64> for HumanReadableDuration

Used to do value-to-value conversions while consuming the input value. It is the reciprocal of Into.

Source§

fn from(value: u64) -> Self

Create an instance for HumanReadableDuration from a u64 field representing the seconds

§Example
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::{AsMinutes, AsSeconds};

let seconds: u64 = 300;
let representation = HumanReadableDuration::from(seconds);

assert_eq!(300, representation.as_seconds());
assert_eq!(5, representation.as_minutes());
Source§

impl From<u8> for HumanReadableDuration

Used to do value-to-value conversions while consuming the input value. It is the reciprocal of Into.

Source§

fn from(value: u8) -> Self

Create an instance for HumanReadableDuration from a u8 field representing the seconds

§Example
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::{AsMinutes, AsSeconds};

let seconds: u8 = 120;
let representation = HumanReadableDuration::from(seconds);

assert_eq!(120, representation.as_seconds());
assert_eq!(2, representation.as_minutes());
Source§

impl FromStr for HumanReadableDuration

Parse a value from a string

FromStr’s from_str method is often used implicitly, through str’s parse method. See parse’s documentation for examples.

Source§

fn from_str(value: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of the HumanReadableDuration type.

If parsing succeeds, return the value inside Ok, otherwise when the string is ill-formatted return an error specific to the inside Err.

§Examples
use std::str::FromStr;
use human_readable_time::HumanReadableDuration;
use human_readable_time::traits::AsSeconds;

let s = "50s";
let x = HumanReadableDuration::from_str(s).unwrap();

assert_eq!(50, x.as_seconds());
Source§

type Err = ParseHumanReadableDurationError

The associated error which can be returned from parsing.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.