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§
Sourcefn seconds(&self) -> Option<Duration>
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());
Sourcefn milliseconds(&self) -> Option<Duration>
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());
Sourcefn microseconds(&self) -> Option<Duration>
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());
Sourcefn nanoseconds(&self) -> Option<Duration>
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());
Sourcefn minutes(&self) -> Option<Duration>
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)));