@@ -94,7 +94,7 @@ impl Duration {
9494 /// ```
9595 #[ stable( feature = "duration" , since = "1.3.0" ) ]
9696 #[ inline]
97- pub fn from_secs ( secs : u64 ) -> Duration {
97+ pub const fn from_secs ( secs : u64 ) -> Duration {
9898 Duration { secs : secs, nanos : 0 }
9999 }
100100
@@ -112,10 +112,11 @@ impl Duration {
112112 /// ```
113113 #[ stable( feature = "duration" , since = "1.3.0" ) ]
114114 #[ inline]
115- pub fn from_millis ( millis : u64 ) -> Duration {
116- let secs = millis / MILLIS_PER_SEC ;
117- let nanos = ( ( millis % MILLIS_PER_SEC ) as u32 ) * NANOS_PER_MILLI ;
118- Duration { secs : secs, nanos : nanos }
115+ pub const fn from_millis ( millis : u64 ) -> Duration {
116+ Duration {
117+ secs : millis / MILLIS_PER_SEC ,
118+ nanos : ( ( millis % MILLIS_PER_SEC ) as u32 ) * NANOS_PER_MILLI ,
119+ }
119120 }
120121
121122 /// Creates a new `Duration` from the specified number of microseconds.
@@ -133,10 +134,11 @@ impl Duration {
133134 /// ```
134135 #[ unstable( feature = "duration_from_micros" , issue = "44400" ) ]
135136 #[ inline]
136- pub fn from_micros ( micros : u64 ) -> Duration {
137- let secs = micros / MICROS_PER_SEC ;
138- let nanos = ( ( micros % MICROS_PER_SEC ) as u32 ) * NANOS_PER_MICRO ;
139- Duration { secs : secs, nanos : nanos }
137+ pub const fn from_micros ( micros : u64 ) -> Duration {
138+ Duration {
139+ secs : micros / MICROS_PER_SEC ,
140+ nanos : ( ( micros % MICROS_PER_SEC ) as u32 ) * NANOS_PER_MICRO ,
141+ }
140142 }
141143
142144 /// Creates a new `Duration` from the specified number of nanoseconds.
@@ -154,10 +156,11 @@ impl Duration {
154156 /// ```
155157 #[ unstable( feature = "duration_extras" , issue = "46507" ) ]
156158 #[ inline]
157- pub fn from_nanos ( nanos : u64 ) -> Duration {
158- let secs = nanos / ( NANOS_PER_SEC as u64 ) ;
159- let nanos = ( nanos % ( NANOS_PER_SEC as u64 ) ) as u32 ;
160- Duration { secs : secs, nanos : nanos }
159+ pub const fn from_nanos ( nanos : u64 ) -> Duration {
160+ Duration {
161+ secs : nanos / ( NANOS_PER_SEC as u64 ) ,
162+ nanos : ( nanos % ( NANOS_PER_SEC as u64 ) ) as u32 ,
163+ }
161164 }
162165
163166 /// Returns the number of _whole_ seconds contained by this `Duration`.
0 commit comments