@@ -73,7 +73,7 @@ impl Duration {
73
73
/// ```
74
74
#[ stable( feature = "duration" , since = "1.3.0" ) ]
75
75
#[ inline]
76
- pub fn new ( secs : u64 , nanos : u32 ) -> Duration {
76
+ pub const fn new ( secs : u64 , nanos : u32 ) -> Duration {
77
77
let secs = secs. checked_add ( ( nanos / NANOS_PER_SEC ) as u64 )
78
78
. expect ( "overflow in Duration::new" ) ;
79
79
let nanos = nanos % NANOS_PER_SEC ;
@@ -94,7 +94,7 @@ impl Duration {
94
94
/// ```
95
95
#[ stable( feature = "duration" , since = "1.3.0" ) ]
96
96
#[ inline]
97
- pub fn from_secs ( secs : u64 ) -> Duration {
97
+ pub const fn from_secs ( secs : u64 ) -> Duration {
98
98
Duration { secs : secs, nanos : 0 }
99
99
}
100
100
@@ -112,7 +112,7 @@ impl Duration {
112
112
/// ```
113
113
#[ stable( feature = "duration" , since = "1.3.0" ) ]
114
114
#[ inline]
115
- pub fn from_millis ( millis : u64 ) -> Duration {
115
+ pub const fn from_millis ( millis : u64 ) -> Duration {
116
116
let secs = millis / MILLIS_PER_SEC ;
117
117
let nanos = ( ( millis % MILLIS_PER_SEC ) as u32 ) * NANOS_PER_MILLI ;
118
118
Duration { secs : secs, nanos : nanos }
@@ -133,7 +133,7 @@ impl Duration {
133
133
/// ```
134
134
#[ unstable( feature = "duration_from_micros" , issue = "44400" ) ]
135
135
#[ inline]
136
- pub fn from_micros ( micros : u64 ) -> Duration {
136
+ pub const fn from_micros ( micros : u64 ) -> Duration {
137
137
let secs = micros / MICROS_PER_SEC ;
138
138
let nanos = ( ( micros % MICROS_PER_SEC ) as u32 ) * NANOS_PER_MICRO ;
139
139
Duration { secs : secs, nanos : nanos }
@@ -154,7 +154,7 @@ impl Duration {
154
154
/// ```
155
155
#[ unstable( feature = "duration_extras" , issue = "46507" ) ]
156
156
#[ inline]
157
- pub fn from_nanos ( nanos : u64 ) -> Duration {
157
+ pub const fn from_nanos ( nanos : u64 ) -> Duration {
158
158
let secs = nanos / ( NANOS_PER_SEC as u64 ) ;
159
159
let nanos = ( nanos % ( NANOS_PER_SEC as u64 ) ) as u32 ;
160
160
Duration { secs : secs, nanos : nanos }
0 commit comments