Struct human_readable_time::HumanReadableDuration[][src]

pub struct HumanReadableDuration { /* fields omitted */ }
Expand description

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

Implementations

Get the duration time in seconds

Example
use std::str::FromStr;
use human_readable_time::HumanReadableDuration;

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

assert_eq!(10, duration.unwrap().seconds());

Get the duration time in full minutes

Example
use std::str::FromStr;
use human_readable_time::HumanReadableDuration;

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

assert_eq!(1, duration.unwrap().minutes());

Trait Implementations

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

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

Example
use human_readable_time::HumanReadableDuration;

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

assert_eq!(300, representation.seconds());
assert_eq!(5, representation.minutes());

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

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

Example
use human_readable_time::HumanReadableDuration;

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

assert_eq!(300, representation.seconds());
assert_eq!(5, representation.minutes());

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

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

Example
use human_readable_time::HumanReadableDuration;

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

assert_eq!(300, representation.seconds());
assert_eq!(5, representation.minutes());

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

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

Example
use human_readable_time::HumanReadableDuration;

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

assert_eq!(120, representation.seconds());
assert_eq!(2, representation.minutes());

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.

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;

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

assert_eq!(50, x.seconds());

The associated error which can be returned from parsing.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.