@@ -53,26 +53,28 @@ impl Duration {
53
53
/// in a second), then it will carry over into the seconds provided.
54
54
#[ stable( feature = "duration" , since = "1.3.0" ) ]
55
55
#[ inline]
56
- pub fn new ( secs : u64 , nanos : u32 ) -> Duration {
57
- let secs = secs + ( nanos / NANOS_PER_SEC ) as u64 ;
58
- let nanos = nanos % NANOS_PER_SEC ;
59
- Duration { secs : secs, nanos : nanos }
56
+ pub const fn new ( secs : u64 , nanos : u32 ) -> Duration {
57
+ Duration {
58
+ secs : secs + ( nanos / NANOS_PER_SEC ) as u64 ,
59
+ nanos : nanos % NANOS_PER_SEC ,
60
+ }
60
61
}
61
62
62
63
/// Creates a new `Duration` from the specified number of seconds.
63
64
#[ stable( feature = "duration" , since = "1.3.0" ) ]
64
65
#[ inline]
65
- pub fn from_secs ( secs : u64 ) -> Duration {
66
+ pub const fn from_secs ( secs : u64 ) -> Duration {
66
67
Duration { secs : secs, nanos : 0 }
67
68
}
68
69
69
70
/// Creates a new `Duration` from the specified number of milliseconds.
70
71
#[ stable( feature = "duration" , since = "1.3.0" ) ]
71
72
#[ inline]
72
- pub fn from_millis ( millis : u64 ) -> Duration {
73
- let secs = millis / MILLIS_PER_SEC ;
74
- let nanos = ( ( millis % MILLIS_PER_SEC ) as u32 ) * NANOS_PER_MILLI ;
75
- Duration { secs : secs, nanos : nanos }
73
+ pub const fn from_millis ( millis : u64 ) -> Duration {
74
+ Duration {
75
+ secs : millis / MILLIS_PER_SEC ,
76
+ nanos : ( ( millis % MILLIS_PER_SEC ) as u32 ) * NANOS_PER_MILLI ,
77
+ }
76
78
}
77
79
78
80
/// Returns the number of whole seconds represented by this duration.
@@ -81,7 +83,7 @@ impl Duration {
81
83
/// nanoseconds are not represented in the returned value).
82
84
#[ stable( feature = "duration" , since = "1.3.0" ) ]
83
85
#[ inline]
84
- pub fn as_secs ( & self ) -> u64 { self . secs }
86
+ pub const fn as_secs ( & self ) -> u64 { self . secs }
85
87
86
88
/// Returns the nanosecond precision represented by this duration.
87
89
///
@@ -90,7 +92,7 @@ impl Duration {
90
92
/// fractional portion of a second (e.g. it is less than one billion).
91
93
#[ stable( feature = "duration" , since = "1.3.0" ) ]
92
94
#[ inline]
93
- pub fn subsec_nanos ( & self ) -> u32 { self . nanos }
95
+ pub const fn subsec_nanos ( & self ) -> u32 { self . nanos }
94
96
}
95
97
96
98
#[ stable( feature = "duration" , since = "1.3.0" ) ]
0 commit comments