Trait actix_web::cookie::time::ext::NumericalStdDuration

source ·
pub trait NumericalStdDuration: Sealed {
    // Required methods
    fn std_nanoseconds(self) -> Duration;
    fn std_microseconds(self) -> Duration;
    fn std_milliseconds(self) -> Duration;
    fn std_seconds(self) -> Duration;
    fn std_minutes(self) -> Duration;
    fn std_hours(self) -> Duration;
    fn std_days(self) -> Duration;
    fn std_weeks(self) -> Duration;
}
Available on crate feature cookies only.
Expand description

Create std::time::Durations from numeric literals.

§Examples

Basic construction of std::time::Durations.

assert_eq!(5.std_nanoseconds(), Duration::from_nanos(5));
assert_eq!(5.std_microseconds(), Duration::from_micros(5));
assert_eq!(5.std_milliseconds(), Duration::from_millis(5));
assert_eq!(5.std_seconds(), Duration::from_secs(5));
assert_eq!(5.std_minutes(), Duration::from_secs(5 * 60));
assert_eq!(5.std_hours(), Duration::from_secs(5 * 3_600));
assert_eq!(5.std_days(), Duration::from_secs(5 * 86_400));
assert_eq!(5.std_weeks(), Duration::from_secs(5 * 604_800));

Just like any other std::time::Duration, they can be added, subtracted, etc.

assert_eq!(
    2.std_seconds() + 500.std_milliseconds(),
    2_500.std_milliseconds()
);
assert_eq!(
    2.std_seconds() - 500.std_milliseconds(),
    1_500.std_milliseconds()
);

When called on floating point values, any remainder of the floating point value will be truncated. Keep in mind that floating point numbers are inherently imprecise and have limited capacity.

Required Methods§

source

fn std_nanoseconds(self) -> Duration

Create a std::time::Duration from the number of nanoseconds.

source

fn std_microseconds(self) -> Duration

Create a std::time::Duration from the number of microseconds.

source

fn std_milliseconds(self) -> Duration

Create a std::time::Duration from the number of milliseconds.

source

fn std_seconds(self) -> Duration

Create a std::time::Duration from the number of seconds.

source

fn std_minutes(self) -> Duration

Create a std::time::Duration from the number of minutes.

source

fn std_hours(self) -> Duration

Create a std::time::Duration from the number of hours.

source

fn std_days(self) -> Duration

Create a std::time::Duration from the number of days.

source

fn std_weeks(self) -> Duration

Create a std::time::Duration from the number of weeks.

Implementations on Foreign Types§

source§

impl NumericalStdDuration for f64

source§

fn std_nanoseconds(self) -> Duration

§Panics

This will panic if self is negative.

source§

fn std_microseconds(self) -> Duration

§Panics

This will panic if self is negative.

source§

fn std_milliseconds(self) -> Duration

§Panics

This will panic if self is negative.

source§

fn std_seconds(self) -> Duration

§Panics

This will panic if self is negative.

source§

fn std_minutes(self) -> Duration

§Panics

This will panic if self is negative.

source§

fn std_hours(self) -> Duration

§Panics

This will panic if self is negative.

source§

fn std_days(self) -> Duration

§Panics

This will panic if self is negative.

source§

fn std_weeks(self) -> Duration

§Panics

This will panic if self is negative.

source§

impl NumericalStdDuration for u64

source§

fn std_minutes(self) -> Duration

§Panics

This may panic if an overflow occurs.

source§

fn std_hours(self) -> Duration

§Panics

This may panic if an overflow occurs.

source§

fn std_days(self) -> Duration

§Panics

This may panic if an overflow occurs.

source§

fn std_weeks(self) -> Duration

§Panics

This may panic if an overflow occurs.

source§

fn std_nanoseconds(self) -> Duration

source§

fn std_microseconds(self) -> Duration

source§

fn std_milliseconds(self) -> Duration

source§

fn std_seconds(self) -> Duration

Implementors§