Trait DurationNumExtFallible

Source
pub trait DurationNumExtFallible {
    // Required methods
    fn seconds(&self) -> Option<Duration>;
    fn milliseconds(&self) -> Option<Duration>;
    fn microseconds(&self) -> Option<Duration>;
    fn nanoseconds(&self) -> Option<Duration>;
    fn minutes(&self) -> Option<Duration>;
    fn hours(&self) -> Option<Duration>;
    fn days(&self) -> Option<Duration>;
}
Expand description

Extension methods for constructing std::time::Duration with numbers.

§Note

This trait is not implemented for the Duration, for extension methods operating on a Duration, see crate::time::DurationExt for more information.

§Warning

Unlike the DurationNumExt, this trait’s method returns an Option<Duration>. Numbers that may be too large to be represented like num::BigInt or may be negative like signed integers will implement this trait.

Required Methods§

Source

fn seconds(&self) -> Option<Duration>

Create a Duration, using the postfix syntax.

§Example
use rs_std_ext::time::DurationNumExtFallible;
use std::time::Duration;

assert_eq!(10u128.seconds(), Some(Duration::from_secs(10u64)));
assert!(u128::MAX.seconds().is_none());
Source

fn milliseconds(&self) -> Option<Duration>

Create a Duration, using the postfix syntax.

§Example
use rs_std_ext::time::DurationNumExtFallible;
use std::time::Duration;


assert_eq!(10u128.milliseconds(), Some(Duration::from_millis(10u64)));
assert!(u128::MAX.milliseconds().is_none());
Source

fn microseconds(&self) -> Option<Duration>

Create a Duration, using the postfix syntax.

§Example
use rs_std_ext::time::DurationNumExtFallible;
use std::time::Duration;

assert_eq!(10u128.microseconds(), Some(Duration::from_micros(10u64)));
assert!(u128::MAX.microseconds().is_none());
Source

fn nanoseconds(&self) -> Option<Duration>

Create a Duration, using the postfix syntax.

§Example
use rs_std_ext::time::DurationNumExtFallible;
use std::time::Duration;

assert_eq!(10u128.nanoseconds(), Some(Duration::from_nanos(10u64)));
assert!(u128::MAX.nanoseconds().is_none());
Source

fn minutes(&self) -> Option<Duration>

Create a Duration, using the postfix syntax.

§Example
use rs_std_ext::time::DurationNumExtFallible;
use std::time::Duration;

assert_eq!(10u128.minutes(), Some(Duration::from_secs(10u64 * 60)));
Source

fn hours(&self) -> Option<Duration>

Create a Duration, using the postfix syntax.

§Example
use rs_std_ext::time::DurationNumExtFallible;
use std::time::Duration;

assert_eq!(10u128.hours(), Some(Duration::from_secs(10u64 * 60 * 60)));
Source

fn days(&self) -> Option<Duration>

Create a Duration, using the postfix syntax.

§Example
use rs_std_ext::time::DurationNumExtFallible;
use std::time::Duration;

assert_eq!(10u128.days(), Some(Duration::from_secs(10u64 * 60 * 60 * 24)));

Implementations on Foreign Types§

Source§

impl DurationNumExtFallible for f32

Source§

impl DurationNumExtFallible for f64

Source§

impl DurationNumExtFallible for i8

Source§

impl DurationNumExtFallible for i16

Source§

impl DurationNumExtFallible for i32

Source§

impl DurationNumExtFallible for i64

Source§

impl DurationNumExtFallible for i128

Source§

impl DurationNumExtFallible for u8

Source§

impl DurationNumExtFallible for u16

Source§

impl DurationNumExtFallible for u32

Source§

impl DurationNumExtFallible for u64

Source§

impl DurationNumExtFallible for u128

Source§

impl DurationNumExtFallible for BigInt

Source§

impl DurationNumExtFallible for BigUint

Implementors§