ParserUnits

Struct ParserUnits 

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

Used to customize the parser’s units and their values.

Implementations§

Source§

impl ParserUnits

Source

pub fn new() -> Self

Returns a ParserUnits with no default units (empty map).

Source

pub fn add_unit(&mut self, k: &'static str, v: Duration)

Insert/update a unit and its value.

For example, to add a unit ‘day’ with a duration of 24 hours:

use durstr::ParserUnits;
use std::time::Duration;

let mut units = ParserUnits::default();
units.add_unit("day", Duration::from_secs(3600) * 24);

Trait Implementations§

Source§

impl Default for ParserUnits

Source§

fn default() -> Self

Provides the default set of units for parsing durations.

Default Units

  • ms, msec(s), millisecond(s)
  • s, sec(s), second(s)
  • m, min(s), minute(s)
  • h, hr(s), hour(s)

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.