@@ -103,33 +103,9 @@ impl Sub<Duration> for MonotonicTime {
103103 }
104104}
105105
106- #[ cfg( not( feature = "no-std" ) ) ]
107- impl Time for std:: time:: Instant {
108- fn now ( ) -> Self {
109- std:: time:: Instant :: now ( )
110- }
111-
112- fn duration_since ( & self , earlier : Self ) -> Duration {
113- // On rust prior to 1.60 `Instant::duration_since` will panic if time goes backwards.
114- // However, we support rust versions prior to 1.60 and some users appear to have "monotonic
115- // clocks" that go backwards in practice (likely relatively ancient kernels/etc). Thus, we
116- // manually check for time going backwards here and return a duration of zero in that case.
117- let now = Self :: now ( ) ;
118- if now > earlier { now - earlier } else { Duration :: from_secs ( 0 ) }
119- }
120-
121- fn duration_since_epoch ( ) -> Duration {
122- use std:: time:: SystemTime ;
123- SystemTime :: now ( ) . duration_since ( SystemTime :: UNIX_EPOCH ) . unwrap ( )
124- }
125- fn elapsed ( & self ) -> Duration {
126- std:: time:: Instant :: elapsed ( self )
127- }
128- }
129-
130106#[ cfg( test) ]
131107pub mod tests {
132- use super :: { Time , Eternity , MonotonicTime } ;
108+ use super :: { Time , Eternity } ;
133109
134110 use core:: time:: Duration ;
135111 use core:: ops:: Sub ;
@@ -201,8 +177,9 @@ pub mod tests {
201177 }
202178
203179 #[ test]
180+ #[ cfg( not( feature = "no-std" ) ) ]
204181 fn monotonic_time_go_backward ( ) {
205- let now = MonotonicTime :: now ( ) ;
182+ let now = super :: MonotonicTime :: now ( ) ;
206183 let ten_years = Duration :: from_secs ( 10 * 365 * 24 * 60 * 60 ) ;
207184 let _past = now - ten_years;
208185 }
0 commit comments