@@ -9,16 +9,16 @@ use crate::convert::TryInto;
9
9
const NSEC_PER_SEC : u64 = 1_000_000_000 ;
10
10
11
11
#[ derive( Copy , Clone ) ]
12
- struct Timespec {
13
- t : libc:: timespec ,
12
+ pub ( in crate :: sys :: unix ) struct Timespec {
13
+ pub t : libc:: timespec ,
14
14
}
15
15
16
16
impl Timespec {
17
17
const fn zero ( ) -> Timespec {
18
18
Timespec { t : libc:: timespec { tv_sec : 0 , tv_nsec : 0 } }
19
19
}
20
20
21
- fn sub_timespec ( & self , other : & Timespec ) -> Result < Duration , Duration > {
21
+ pub fn sub_timespec ( & self , other : & Timespec ) -> Result < Duration , Duration > {
22
22
if self >= other {
23
23
// NOTE(eddyb) two aspects of this `if`-`else` are required for LLVM
24
24
// to optimize it into a branchless form (see also #75545):
@@ -51,7 +51,7 @@ impl Timespec {
51
51
}
52
52
}
53
53
54
- fn checked_add_duration ( & self , other : & Duration ) -> Option < Timespec > {
54
+ pub fn checked_add_duration ( & self , other : & Duration ) -> Option < Timespec > {
55
55
let mut secs = other
56
56
. as_secs ( )
57
57
. try_into ( ) // <- target type would be `libc::time_t`
@@ -68,7 +68,7 @@ impl Timespec {
68
68
Some ( Timespec { t : libc:: timespec { tv_sec : secs, tv_nsec : nsec as _ } } )
69
69
}
70
70
71
- fn checked_sub_duration ( & self , other : & Duration ) -> Option < Timespec > {
71
+ pub fn checked_sub_duration ( & self , other : & Duration ) -> Option < Timespec > {
72
72
let mut secs = other
73
73
. as_secs ( )
74
74
. try_into ( ) // <- target type would be `libc::time_t`
@@ -285,7 +285,7 @@ mod inner {
285
285
286
286
impl Instant {
287
287
pub fn now ( ) -> Instant {
288
- Instant { t : now ( libc:: CLOCK_MONOTONIC ) }
288
+ Instant { t : Timespec :: now ( libc:: CLOCK_MONOTONIC ) }
289
289
}
290
290
291
291
pub fn checked_sub_instant ( & self , other : & Instant ) -> Option < Duration > {
@@ -299,10 +299,6 @@ mod inner {
299
299
pub fn checked_sub_duration ( & self , other : & Duration ) -> Option < Instant > {
300
300
Some ( Instant { t : self . t . checked_sub_duration ( other) ? } )
301
301
}
302
-
303
- pub ( in crate :: sys:: unix) fn as_timespec ( & self ) -> libc:: timespec {
304
- self . t . t
305
- }
306
302
}
307
303
308
304
impl fmt:: Debug for Instant {
@@ -316,7 +312,7 @@ mod inner {
316
312
317
313
impl SystemTime {
318
314
pub fn now ( ) -> SystemTime {
319
- SystemTime { t : now ( libc:: CLOCK_REALTIME ) }
315
+ SystemTime { t : Timespec :: now ( libc:: CLOCK_REALTIME ) }
320
316
}
321
317
322
318
pub fn sub_time ( & self , other : & SystemTime ) -> Result < Duration , Duration > {
@@ -352,9 +348,11 @@ mod inner {
352
348
#[ cfg( any( target_os = "dragonfly" , target_os = "espidf" ) ) ]
353
349
pub type clock_t = libc:: c_ulong ;
354
350
355
- fn now ( clock : clock_t ) -> Timespec {
356
- let mut t = Timespec { t : libc:: timespec { tv_sec : 0 , tv_nsec : 0 } } ;
357
- cvt ( unsafe { libc:: clock_gettime ( clock, & mut t. t ) } ) . unwrap ( ) ;
358
- t
351
+ impl Timespec {
352
+ pub fn now ( clock : clock_t ) -> Timespec {
353
+ let mut t = Timespec { t : libc:: timespec { tv_sec : 0 , tv_nsec : 0 } } ;
354
+ cvt ( unsafe { libc:: clock_gettime ( clock, & mut t. t ) } ) . unwrap ( ) ;
355
+ t
356
+ }
359
357
}
360
358
}
0 commit comments