Movatterモバイル変換


[0]ホーム

URL:


Duration

core::time

StructDuration 

1.25.0 ·Source
pub struct Duration {/* private fields */ }
Expand description

ADuration type to represent a span of time, typically used for systemtimeouts.

EachDuration is composed of a whole number of seconds and a fractional partrepresented in nanoseconds. If the underlying system does not supportnanosecond-level precision, APIs binding a system timeout will typically round upthe number of nanoseconds.

Durations implement many common traits, includingAdd,Sub, and otherops traits. It implementsDefault by returning a zero-lengthDuration.

§Examples

usestd::time::Duration;letfive_seconds = Duration::new(5,0);letfive_seconds_and_five_nanos = five_seconds + Duration::new(0,5);assert_eq!(five_seconds_and_five_nanos.as_secs(),5);assert_eq!(five_seconds_and_five_nanos.subsec_nanos(),5);letten_millis = Duration::from_millis(10);

§FormattingDuration values

Duration intentionally does not have aDisplay impl, as there are avariety of ways to format spans of time for human readability.Durationprovides aDebug impl that shows the full precision of the value.

TheDebug output uses the non-ASCII “µs” suffix for microseconds. If yourprogram output may appear in contexts that cannot rely on full Unicodecompatibility, you may wish to formatDuration objects yourself or use acrate to do so.

Implementations§

Source§

implDuration

Source

pub constSECOND:Duration

🔬This is a nightly-only experimental API. (duration_constants #57391)

The duration of one second.

§Examples
#![feature(duration_constants)]usestd::time::Duration;assert_eq!(Duration::SECOND, Duration::from_secs(1));
Source

pub constMILLISECOND:Duration

🔬This is a nightly-only experimental API. (duration_constants #57391)

The duration of one millisecond.

§Examples
#![feature(duration_constants)]usestd::time::Duration;assert_eq!(Duration::MILLISECOND, Duration::from_millis(1));
Source

pub constMICROSECOND:Duration

🔬This is a nightly-only experimental API. (duration_constants #57391)

The duration of one microsecond.

§Examples
#![feature(duration_constants)]usestd::time::Duration;assert_eq!(Duration::MICROSECOND, Duration::from_micros(1));
Source

pub constNANOSECOND:Duration

🔬This is a nightly-only experimental API. (duration_constants #57391)

The duration of one nanosecond.

§Examples
#![feature(duration_constants)]usestd::time::Duration;assert_eq!(Duration::NANOSECOND, Duration::from_nanos(1));
1.53.0 ·Source

pub constZERO:Duration

A duration of zero time.

§Examples
usestd::time::Duration;letduration = Duration::ZERO;assert!(duration.is_zero());assert_eq!(duration.as_nanos(),0);
1.53.0 ·Source

pub constMAX:Duration

The maximum duration.

May vary by platform as necessary. Must be able to contain the difference betweentwo instances ofInstant or two instances ofSystemTime.This constraint gives it a value of about 584,942,417,355 years in practice,which is currently used on all platforms.

§Examples
usestd::time::Duration;assert_eq!(Duration::MAX, Duration::new(u64::MAX,1_000_000_000-1));
1.3.0 (const: 1.58.0) ·Source

pub const fnnew(secs:u64, nanos:u32) ->Duration

Creates a newDuration from the specified number of whole seconds andadditional nanoseconds.

If the number of nanoseconds is greater than 1 billion (the number ofnanoseconds in a second), then it will carry over into the seconds provided.

§Panics

This constructor will panic if the carry from the nanoseconds overflowsthe seconds counter.

§Examples
usestd::time::Duration;letfive_seconds = Duration::new(5,0);
1.3.0 (const: 1.32.0) ·Source

pub const fnfrom_secs(secs:u64) ->Duration

Creates a newDuration from the specified number of whole seconds.

§Examples
usestd::time::Duration;letduration = Duration::from_secs(5);assert_eq!(5, duration.as_secs());assert_eq!(0, duration.subsec_nanos());
1.3.0 (const: 1.32.0) ·Source

pub const fnfrom_millis(millis:u64) ->Duration

Creates a newDuration from the specified number of milliseconds.

§Examples
usestd::time::Duration;letduration = Duration::from_millis(2_569);assert_eq!(2, duration.as_secs());assert_eq!(569_000_000, duration.subsec_nanos());
1.27.0 (const: 1.32.0) ·Source

pub const fnfrom_micros(micros:u64) ->Duration

Creates a newDuration from the specified number of microseconds.

§Examples
usestd::time::Duration;letduration = Duration::from_micros(1_000_002);assert_eq!(1, duration.as_secs());assert_eq!(2_000, duration.subsec_nanos());
1.27.0 (const: 1.32.0) ·Source

pub const fnfrom_nanos(nanos:u64) ->Duration

Creates a newDuration from the specified number of nanoseconds.

Note: Using this on the return value ofas_nanos() might cause unexpected behavior:as_nanos() returns a u128, and can return values that do not fit in u64, e.g. 585 years.Instead, consider using the patternDuration::new(d.as_secs(), d.subsec_nanos())if you cannot copy/clone the Duration directly.

§Examples
usestd::time::Duration;letduration = Duration::from_nanos(1_000_000_123);assert_eq!(1, duration.as_secs());assert_eq!(123, duration.subsec_nanos());
Source

pub const fnfrom_nanos_u128(nanos:u128) ->Duration

🔬This is a nightly-only experimental API. (duration_from_nanos_u128 #139201)

Creates a newDuration from the specified number of nanoseconds.

§Panics

Panics if the given number of nanoseconds is greater thanDuration::MAX.

§Examples
#![feature(duration_from_nanos_u128)]usestd::time::Duration;letnanos =10_u128.pow(24) +321;letduration = Duration::from_nanos_u128(nanos);assert_eq!(10_u64.pow(15), duration.as_secs());assert_eq!(321, duration.subsec_nanos());
Source

pub const fnfrom_weeks(weeks:u64) ->Duration

🔬This is a nightly-only experimental API. (duration_constructors #120301)

Creates a newDuration from the specified number of weeks.

§Panics

Panics if the given number of weeks overflows theDuration size.

§Examples
#![feature(duration_constructors)]usestd::time::Duration;letduration = Duration::from_weeks(4);assert_eq!(4*7*24*60*60, duration.as_secs());assert_eq!(0, duration.subsec_nanos());
Source

pub const fnfrom_days(days:u64) ->Duration

🔬This is a nightly-only experimental API. (duration_constructors #120301)

Creates a newDuration from the specified number of days.

§Panics

Panics if the given number of days overflows theDuration size.

§Examples
#![feature(duration_constructors)]usestd::time::Duration;letduration = Duration::from_days(7);assert_eq!(7*24*60*60, duration.as_secs());assert_eq!(0, duration.subsec_nanos());
1.91.0 (const: 1.91.0) ·Source

pub const fnfrom_hours(hours:u64) ->Duration

Creates a newDuration from the specified number of hours.

§Panics

Panics if the given number of hours overflows theDuration size.

§Examples
usestd::time::Duration;letduration = Duration::from_hours(6);assert_eq!(6*60*60, duration.as_secs());assert_eq!(0, duration.subsec_nanos());
1.91.0 (const: 1.91.0) ·Source

pub const fnfrom_mins(mins:u64) ->Duration

Creates a newDuration from the specified number of minutes.

§Panics

Panics if the given number of minutes overflows theDuration size.

§Examples
usestd::time::Duration;letduration = Duration::from_mins(10);assert_eq!(10*60, duration.as_secs());assert_eq!(0, duration.subsec_nanos());
1.53.0 (const: 1.53.0) ·Source

pub const fnis_zero(&self) ->bool

Returns true if thisDuration spans no time.

§Examples
usestd::time::Duration;assert!(Duration::ZERO.is_zero());assert!(Duration::new(0,0).is_zero());assert!(Duration::from_nanos(0).is_zero());assert!(Duration::from_secs(0).is_zero());assert!(!Duration::new(1,1).is_zero());assert!(!Duration::from_nanos(1).is_zero());assert!(!Duration::from_secs(1).is_zero());
1.3.0 (const: 1.32.0) ·Source

pub const fnas_secs(&self) ->u64

Returns the number ofwhole seconds contained by thisDuration.

The returned value does not include the fractional (nanosecond) part of theduration, which can be obtained usingsubsec_nanos.

§Examples
usestd::time::Duration;letduration = Duration::new(5,730_023_852);assert_eq!(duration.as_secs(),5);

To determine the total number of seconds represented by theDurationincluding the fractional part, useas_secs_f64 oras_secs_f32

1.27.0 (const: 1.32.0) ·Source

pub const fnsubsec_millis(&self) ->u32

Returns the fractional part of thisDuration, in whole milliseconds.

This method doesnot return the length of the duration whenrepresented by milliseconds. The returned number always represents afractional portion of a second (i.e., it is less than one thousand).

§Examples
usestd::time::Duration;letduration = Duration::from_millis(5_432);assert_eq!(duration.as_secs(),5);assert_eq!(duration.subsec_millis(),432);
1.27.0 (const: 1.32.0) ·Source

pub const fnsubsec_micros(&self) ->u32

Returns the fractional part of thisDuration, in whole microseconds.

This method doesnot return the length of the duration whenrepresented by microseconds. The returned number always represents afractional portion of a second (i.e., it is less than one million).

§Examples
usestd::time::Duration;letduration = Duration::from_micros(1_234_567);assert_eq!(duration.as_secs(),1);assert_eq!(duration.subsec_micros(),234_567);
1.3.0 (const: 1.32.0) ·Source

pub const fnsubsec_nanos(&self) ->u32

Returns the fractional part of thisDuration, in nanoseconds.

This method doesnot return the length of the duration whenrepresented by nanoseconds. The returned number always represents afractional portion of a second (i.e., it is less than one billion).

§Examples
usestd::time::Duration;letduration = Duration::from_millis(5_010);assert_eq!(duration.as_secs(),5);assert_eq!(duration.subsec_nanos(),10_000_000);
1.33.0 (const: 1.33.0) ·Source

pub const fnas_millis(&self) ->u128

Returns the total number of whole milliseconds contained by thisDuration.

§Examples
usestd::time::Duration;letduration = Duration::new(5,730_023_852);assert_eq!(duration.as_millis(),5_730);
1.33.0 (const: 1.33.0) ·Source

pub const fnas_micros(&self) ->u128

Returns the total number of whole microseconds contained by thisDuration.

§Examples
usestd::time::Duration;letduration = Duration::new(5,730_023_852);assert_eq!(duration.as_micros(),5_730_023);
1.33.0 (const: 1.33.0) ·Source

pub const fnas_nanos(&self) ->u128

Returns the total number of nanoseconds contained by thisDuration.

§Examples
usestd::time::Duration;letduration = Duration::new(5,730_023_852);assert_eq!(duration.as_nanos(),5_730_023_852);
1.81.0 (const: 1.81.0) ·Source

pub const fnabs_diff(self, other:Duration) ->Duration

Computes the absolute difference betweenself andother.

§Examples
usestd::time::Duration;assert_eq!(Duration::new(100,0).abs_diff(Duration::new(80,0)), Duration::new(20,0));assert_eq!(Duration::new(100,400_000_000).abs_diff(Duration::new(110,0)), Duration::new(9,600_000_000));
1.16.0 (const: 1.58.0) ·Source

pub const fnchecked_add(self, rhs:Duration) ->Option<Duration>

CheckedDuration addition. Computesself + other, returningNoneif overflow occurred.

§Examples
usestd::time::Duration;assert_eq!(Duration::new(0,0).checked_add(Duration::new(0,1)),Some(Duration::new(0,1)));assert_eq!(Duration::new(1,0).checked_add(Duration::new(u64::MAX,0)),None);
1.53.0 (const: 1.58.0) ·Source

pub const fnsaturating_add(self, rhs:Duration) ->Duration

SaturatingDuration addition. Computesself + other, returningDuration::MAXif overflow occurred.

§Examples
#![feature(duration_constants)]usestd::time::Duration;assert_eq!(Duration::new(0,0).saturating_add(Duration::new(0,1)), Duration::new(0,1));assert_eq!(Duration::new(1,0).saturating_add(Duration::new(u64::MAX,0)), Duration::MAX);
1.16.0 (const: 1.58.0) ·Source

pub const fnchecked_sub(self, rhs:Duration) ->Option<Duration>

CheckedDuration subtraction. Computesself - other, returningNoneif the result would be negative or if overflow occurred.

§Examples
usestd::time::Duration;assert_eq!(Duration::new(0,1).checked_sub(Duration::new(0,0)),Some(Duration::new(0,1)));assert_eq!(Duration::new(0,0).checked_sub(Duration::new(0,1)),None);
1.53.0 (const: 1.58.0) ·Source

pub const fnsaturating_sub(self, rhs:Duration) ->Duration

SaturatingDuration subtraction. Computesself - other, returningDuration::ZEROif the result would be negative or if overflow occurred.

§Examples
usestd::time::Duration;assert_eq!(Duration::new(0,1).saturating_sub(Duration::new(0,0)), Duration::new(0,1));assert_eq!(Duration::new(0,0).saturating_sub(Duration::new(0,1)), Duration::ZERO);
1.16.0 (const: 1.58.0) ·Source

pub const fnchecked_mul(self, rhs:u32) ->Option<Duration>

CheckedDuration multiplication. Computesself * other, returningNone if overflow occurred.

§Examples
usestd::time::Duration;assert_eq!(Duration::new(0,500_000_001).checked_mul(2),Some(Duration::new(1,2)));assert_eq!(Duration::new(u64::MAX -1,0).checked_mul(2),None);
1.53.0 (const: 1.58.0) ·Source

pub const fnsaturating_mul(self, rhs:u32) ->Duration

SaturatingDuration multiplication. Computesself * other, returningDuration::MAX if overflow occurred.

§Examples
#![feature(duration_constants)]usestd::time::Duration;assert_eq!(Duration::new(0,500_000_001).saturating_mul(2), Duration::new(1,2));assert_eq!(Duration::new(u64::MAX -1,0).saturating_mul(2), Duration::MAX);
1.16.0 (const: 1.58.0) ·Source

pub const fnchecked_div(self, rhs:u32) ->Option<Duration>

CheckedDuration division. Computesself / other, returningNoneifother == 0.

§Examples
usestd::time::Duration;assert_eq!(Duration::new(2,0).checked_div(2),Some(Duration::new(1,0)));assert_eq!(Duration::new(1,0).checked_div(2),Some(Duration::new(0,500_000_000)));assert_eq!(Duration::new(2,0).checked_div(0),None);
1.38.0 (const: 1.83.0) ·Source

pub const fnas_secs_f64(&self) ->f64

Returns the number of seconds contained by thisDuration asf64.

The returned value includes the fractional (nanosecond) part of the duration.

§Examples
usestd::time::Duration;letdur = Duration::new(2,700_000_000);assert_eq!(dur.as_secs_f64(),2.7);
1.38.0 (const: 1.83.0) ·Source

pub const fnas_secs_f32(&self) ->f32

Returns the number of seconds contained by thisDuration asf32.

The returned value includes the fractional (nanosecond) part of the duration.

§Examples
usestd::time::Duration;letdur = Duration::new(2,700_000_000);assert_eq!(dur.as_secs_f32(),2.7);
Source

pub const fnas_millis_f64(&self) ->f64

🔬This is a nightly-only experimental API. (duration_millis_float #122451)

Returns the number of milliseconds contained by thisDuration asf64.

The returned value includes the fractional (nanosecond) part of the duration.

§Examples
#![feature(duration_millis_float)]usestd::time::Duration;letdur = Duration::new(2,345_678_000);assert_eq!(dur.as_millis_f64(),2_345.678);
Source

pub const fnas_millis_f32(&self) ->f32

🔬This is a nightly-only experimental API. (duration_millis_float #122451)

Returns the number of milliseconds contained by thisDuration asf32.

The returned value includes the fractional (nanosecond) part of the duration.

§Examples
#![feature(duration_millis_float)]usestd::time::Duration;letdur = Duration::new(2,345_678_000);assert_eq!(dur.as_millis_f32(),2_345.678);
1.38.0 ·Source

pub fnfrom_secs_f64(secs:f64) ->Duration

Creates a newDuration from the specified number of seconds representedasf64.

§Panics

This constructor will panic ifsecs is negative, overflowsDuration or not finite.

§Examples
usestd::time::Duration;letres = Duration::from_secs_f64(0.0);assert_eq!(res, Duration::new(0,0));letres = Duration::from_secs_f64(1e-20);assert_eq!(res, Duration::new(0,0));letres = Duration::from_secs_f64(4.2e-7);assert_eq!(res, Duration::new(0,420));letres = Duration::from_secs_f64(2.7);assert_eq!(res, Duration::new(2,700_000_000));letres = Duration::from_secs_f64(3e10);assert_eq!(res, Duration::new(30_000_000_000,0));// subnormal floatletres = Duration::from_secs_f64(f64::from_bits(1));assert_eq!(res, Duration::new(0,0));// conversion uses roundingletres = Duration::from_secs_f64(0.999e-9);assert_eq!(res, Duration::new(0,1));
1.38.0 ·Source

pub fnfrom_secs_f32(secs:f32) ->Duration

Creates a newDuration from the specified number of seconds representedasf32.

§Panics

This constructor will panic ifsecs is negative, overflowsDuration or not finite.

§Examples
usestd::time::Duration;letres = Duration::from_secs_f32(0.0);assert_eq!(res, Duration::new(0,0));letres = Duration::from_secs_f32(1e-20);assert_eq!(res, Duration::new(0,0));letres = Duration::from_secs_f32(4.2e-7);assert_eq!(res, Duration::new(0,420));letres = Duration::from_secs_f32(2.7);assert_eq!(res, Duration::new(2,700_000_048));letres = Duration::from_secs_f32(3e10);assert_eq!(res, Duration::new(30_000_001_024,0));// subnormal floatletres = Duration::from_secs_f32(f32::from_bits(1));assert_eq!(res, Duration::new(0,0));// conversion uses roundingletres = Duration::from_secs_f32(0.999e-9);assert_eq!(res, Duration::new(0,1));
1.38.0 ·Source

pub fnmul_f64(self, rhs:f64) ->Duration

MultipliesDuration byf64.

§Panics

This method will panic if result is negative, overflowsDuration or not finite.

§Examples
usestd::time::Duration;letdur = Duration::new(2,700_000_000);assert_eq!(dur.mul_f64(3.14), Duration::new(8,478_000_000));assert_eq!(dur.mul_f64(3.14e5), Duration::new(847_800,0));
1.38.0 ·Source

pub fnmul_f32(self, rhs:f32) ->Duration

MultipliesDuration byf32.

§Panics

This method will panic if result is negative, overflowsDuration or not finite.

§Examples
usestd::time::Duration;letdur = Duration::new(2,700_000_000);assert_eq!(dur.mul_f32(3.14), Duration::new(8,478_000_641));assert_eq!(dur.mul_f32(3.14e5), Duration::new(847_800,0));
1.38.0 ·Source

pub fndiv_f64(self, rhs:f64) ->Duration

DividesDuration byf64.

§Panics

This method will panic if result is negative, overflowsDuration or not finite.

§Examples
usestd::time::Duration;letdur = Duration::new(2,700_000_000);assert_eq!(dur.div_f64(3.14), Duration::new(0,859_872_611));assert_eq!(dur.div_f64(3.14e5), Duration::new(0,8_599));
1.38.0 ·Source

pub fndiv_f32(self, rhs:f32) ->Duration

DividesDuration byf32.

§Panics

This method will panic if result is negative, overflowsDuration or not finite.

§Examples
usestd::time::Duration;letdur = Duration::new(2,700_000_000);// note that due to rounding errors result is slightly// different from 0.859_872_611assert_eq!(dur.div_f32(3.14), Duration::new(0,859_872_580));assert_eq!(dur.div_f32(3.14e5), Duration::new(0,8_599));
1.80.0 (const: 1.83.0) ·Source

pub const fndiv_duration_f64(self, rhs:Duration) ->f64

DividesDuration byDuration and returnsf64.

§Examples
usestd::time::Duration;letdur1 = Duration::new(2,700_000_000);letdur2 = Duration::new(5,400_000_000);assert_eq!(dur1.div_duration_f64(dur2),0.5);
1.80.0 (const: 1.83.0) ·Source

pub const fndiv_duration_f32(self, rhs:Duration) ->f32

DividesDuration byDuration and returnsf32.

§Examples
usestd::time::Duration;letdur1 = Duration::new(2,700_000_000);letdur2 = Duration::new(5,400_000_000);assert_eq!(dur1.div_duration_f32(dur2),0.5);
Source§

implDuration

1.66.0 ·Source

pub fntry_from_secs_f32(secs:f32) ->Result<Duration,TryFromFloatSecsError>

The checked version offrom_secs_f32.

This constructor will return anErr ifsecs is negative, overflowsDuration or not finite.

§Examples
usestd::time::Duration;letres = Duration::try_from_secs_f32(0.0);assert_eq!(res,Ok(Duration::new(0,0)));letres = Duration::try_from_secs_f32(1e-20);assert_eq!(res,Ok(Duration::new(0,0)));letres = Duration::try_from_secs_f32(4.2e-7);assert_eq!(res,Ok(Duration::new(0,420)));letres = Duration::try_from_secs_f32(2.7);assert_eq!(res,Ok(Duration::new(2,700_000_048)));letres = Duration::try_from_secs_f32(3e10);assert_eq!(res,Ok(Duration::new(30_000_001_024,0)));// subnormal float:letres = Duration::try_from_secs_f32(f32::from_bits(1));assert_eq!(res,Ok(Duration::new(0,0)));letres = Duration::try_from_secs_f32(-5.0);assert!(res.is_err());letres = Duration::try_from_secs_f32(f32::NAN);assert!(res.is_err());letres = Duration::try_from_secs_f32(2e19);assert!(res.is_err());// the conversion uses rounding with tie resolution to evenletres = Duration::try_from_secs_f32(0.999e-9);assert_eq!(res,Ok(Duration::new(0,1)));// this float represents exactly 976562.5e-9letval = f32::from_bits(0x3A80_0000);letres = Duration::try_from_secs_f32(val);assert_eq!(res,Ok(Duration::new(0,976_562)));// this float represents exactly 2929687.5e-9letval = f32::from_bits(0x3B40_0000);letres = Duration::try_from_secs_f32(val);assert_eq!(res,Ok(Duration::new(0,2_929_688)));// this float represents exactly 1.000_976_562_5letval = f32::from_bits(0x3F802000);letres = Duration::try_from_secs_f32(val);assert_eq!(res,Ok(Duration::new(1,976_562)));// this float represents exactly 1.002_929_687_5letval = f32::from_bits(0x3F806000);letres = Duration::try_from_secs_f32(val);assert_eq!(res,Ok(Duration::new(1,2_929_688)));
1.66.0 ·Source

pub fntry_from_secs_f64(secs:f64) ->Result<Duration,TryFromFloatSecsError>

The checked version offrom_secs_f64.

This constructor will return anErr ifsecs is negative, overflowsDuration or not finite.

§Examples
usestd::time::Duration;letres = Duration::try_from_secs_f64(0.0);assert_eq!(res,Ok(Duration::new(0,0)));letres = Duration::try_from_secs_f64(1e-20);assert_eq!(res,Ok(Duration::new(0,0)));letres = Duration::try_from_secs_f64(4.2e-7);assert_eq!(res,Ok(Duration::new(0,420)));letres = Duration::try_from_secs_f64(2.7);assert_eq!(res,Ok(Duration::new(2,700_000_000)));letres = Duration::try_from_secs_f64(3e10);assert_eq!(res,Ok(Duration::new(30_000_000_000,0)));// subnormal floatletres = Duration::try_from_secs_f64(f64::from_bits(1));assert_eq!(res,Ok(Duration::new(0,0)));letres = Duration::try_from_secs_f64(-5.0);assert!(res.is_err());letres = Duration::try_from_secs_f64(f64::NAN);assert!(res.is_err());letres = Duration::try_from_secs_f64(2e19);assert!(res.is_err());// the conversion uses rounding with tie resolution to evenletres = Duration::try_from_secs_f64(0.999e-9);assert_eq!(res,Ok(Duration::new(0,1)));letres = Duration::try_from_secs_f64(0.999_999_999_499);assert_eq!(res,Ok(Duration::new(0,999_999_999)));letres = Duration::try_from_secs_f64(0.999_999_999_501);assert_eq!(res,Ok(Duration::new(1,0)));letres = Duration::try_from_secs_f64(42.999_999_999_499);assert_eq!(res,Ok(Duration::new(42,999_999_999)));letres = Duration::try_from_secs_f64(42.999_999_999_501);assert_eq!(res,Ok(Duration::new(43,0)));// this float represents exactly 976562.5e-9letval = f64::from_bits(0x3F50_0000_0000_0000);letres = Duration::try_from_secs_f64(val);assert_eq!(res,Ok(Duration::new(0,976_562)));// this float represents exactly 2929687.5e-9letval = f64::from_bits(0x3F68_0000_0000_0000);letres = Duration::try_from_secs_f64(val);assert_eq!(res,Ok(Duration::new(0,2_929_688)));// this float represents exactly 1.000_976_562_5letval = f64::from_bits(0x3FF0_0400_0000_0000);letres = Duration::try_from_secs_f64(val);assert_eq!(res,Ok(Duration::new(1,976_562)));// this float represents exactly 1.002_929_687_5letval = f64::from_bits(0x3_FF00_C000_0000_000);letres = Duration::try_from_secs_f64(val);assert_eq!(res,Ok(Duration::new(1,2_929_688)));

Trait Implementations§

1.3.0 (const:unstable) ·Source§

implAdd forDuration

Source§

typeOutput =Duration

The resulting type after applying the+ operator.
Source§

fnadd(self, rhs:Duration) ->Duration

Performs the+ operation.Read more
1.9.0 (const:unstable) ·Source§

implAddAssign forDuration

Source§

fnadd_assign(&mut self, rhs:Duration)

Performs the+= operation.Read more
1.3.0 ·Source§

implClone forDuration

Source§

fnclone(&self) ->Duration

Returns a duplicate of the value.Read more
1.0.0 ·Source§

fnclone_from(&mut self, source: &Self)
where Self:,

Performs copy-assignment fromsource.Read more
1.27.0 ·Source§

implDebug forDuration

Source§

fnfmt(&self, f: &mutFormatter<'_>) ->Result

Formats the value using the given formatter.Read more
1.3.0 ·Source§

implDefault forDuration

Source§

fndefault() ->Duration

Returns the “default value” for a type.Read more
1.3.0 (const:unstable) ·Source§

implDiv<u32> forDuration

Source§

typeOutput =Duration

The resulting type after applying the/ operator.
Source§

fndiv(self, rhs:u32) ->Duration

Performs the/ operation.Read more
1.9.0 (const:unstable) ·Source§

implDivAssign<u32> forDuration

Source§

fndiv_assign(&mut self, rhs:u32)

Performs the/= operation.Read more
1.3.0 ·Source§

implHash forDuration

Source§

fnhash<__H:Hasher>(&self, state:&mut __H)

Feeds this value into the givenHasher.Read more
1.3.0 ·Source§

fnhash_slice<H:Hasher>(data: &[Self], state:&mut H)
where Self:Sized,

Feeds a slice of this type into the givenHasher.Read more
1.31.0 (const:unstable) ·Source§

implMul<Duration> foru32

Source§

typeOutput =Duration

The resulting type after applying the* operator.
Source§

fnmul(self, rhs:Duration) ->Duration

Performs the* operation.Read more
1.3.0 (const:unstable) ·Source§

implMul<u32> forDuration

Source§

typeOutput =Duration

The resulting type after applying the* operator.
Source§

fnmul(self, rhs:u32) ->Duration

Performs the* operation.Read more
1.9.0 (const:unstable) ·Source§

implMulAssign<u32> forDuration

Source§

fnmul_assign(&mut self, rhs:u32)

Performs the*= operation.Read more
1.3.0 ·Source§

implOrd forDuration

Source§

fncmp(&self, other: &Duration) ->Ordering

This method returns anOrdering betweenself andother.Read more
1.21.0 ·Source§

fnmax(self, other: Self) -> Self
where Self:Sized,

Compares and returns the maximum of two values.Read more
1.21.0 ·Source§

fnmin(self, other: Self) -> Self
where Self:Sized,

Compares and returns the minimum of two values.Read more
1.50.0 ·Source§

fnclamp(self, min: Self, max: Self) -> Self
where Self:Sized,

Restrict a value to a certain interval.Read more
1.3.0 ·Source§

implPartialEq forDuration

Source§

fneq(&self, other: &Duration) ->bool

Tests forself andother values to be equal, and is used by==.
1.0.0 ·Source§

fnne(&self, other:&Rhs) ->bool

Tests for!=. The default implementation is almost always sufficient,and should not be overridden without very good reason.
1.3.0 ·Source§

implPartialOrd forDuration

Source§

fnpartial_cmp(&self, other: &Duration) ->Option<Ordering>

This method returns an ordering betweenself andother values if one exists.Read more
1.0.0 ·Source§

fnlt(&self, other:&Rhs) ->bool

Tests less than (forself andother) and is used by the< operator.Read more
1.0.0 ·Source§

fnle(&self, other:&Rhs) ->bool

Tests less than or equal to (forself andother) and is used by the<= operator.Read more
1.0.0 ·Source§

fngt(&self, other:&Rhs) ->bool

Tests greater than (forself andother) and is used by the>operator.Read more
1.0.0 ·Source§

fnge(&self, other:&Rhs) ->bool

Tests greater than or equal to (forself andother) and is used bythe>= operator.Read more
1.3.0 (const:unstable) ·Source§

implSub forDuration

Source§

typeOutput =Duration

The resulting type after applying the- operator.
Source§

fnsub(self, rhs:Duration) ->Duration

Performs the- operation.Read more
1.9.0 (const:unstable) ·Source§

implSubAssign forDuration

Source§

fnsub_assign(&mut self, rhs:Duration)

Performs the-= operation.Read more
1.16.0 ·Source§

impl<'a>Sum<&'aDuration> forDuration

Source§

fnsum<I:Iterator<Item = &'aDuration>>(iter: I) ->Duration

Takes an iterator and generatesSelf from the elements by “summing up”the items.
1.16.0 ·Source§

implSum forDuration

Source§

fnsum<I:Iterator<Item =Duration>>(iter: I) ->Duration

Takes an iterator and generatesSelf from the elements by “summing up”the items.
1.3.0 ·Source§

implCopy forDuration

1.3.0 ·Source§

implEq forDuration

1.3.0 ·Source§

implStructuralPartialEq forDuration

Auto Trait Implementations§

§

implFreeze forDuration

§

implRefUnwindSafe forDuration

§

implSend forDuration

§

implSync forDuration

§

implUnpin forDuration

§

implUnwindSafe forDuration

Blanket Implementations§

Source§

impl<T>Any for T
where T: 'static + ?Sized,

Source§

fntype_id(&self) ->TypeId

Gets theTypeId ofself.Read more
Source§

impl<T>Borrow<T> for T
where T: ?Sized,

Source§

fnborrow(&self) ->&T

Immutably borrows from an owned value.Read more
Source§

impl<T>BorrowMut<T> for T
where T: ?Sized,

Source§

fnborrow_mut(&mut self) ->&mut T

Mutably borrows from an owned value.Read more
Source§

impl<T>CloneToUninit for T
where T:Clone,

Source§

unsafe fnclone_to_uninit(&self, dest:*mutu8)

🔬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment fromself todest.Read more
Source§

impl<T>From<T> for T

Source§

fnfrom(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U>Into<U> for T
where U:From<T>,

Source§

fninto(self) -> U

CallsU::from(self).

That is, this conversion is whatever the implementation ofFrom<T> for U chooses to do.

Source§

impl<T, U>TryFrom<U> for T
where U:Into<T>,

Source§

typeError =Infallible

The type returned in the event of a conversion error.
Source§

fntry_from(value: U) ->Result<T, <T asTryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U>TryInto<U> for T
where U:TryFrom<T>,

Source§

typeError = <U asTryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fntry_into(self) ->Result<U, <U asTryFrom<T>>::Error>

Performs the conversion.

[8]ページ先頭

©2009-2025 Movatter.jp