File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).
6
6
## [ Unreleased] - ReleaseDate
7
7
### Added
8
8
9
+ - Added const constructors for ` TimeSpec ` and ` TimeVal `
10
+ (#[ 1760] ( https://github.com/nix-rust/nix/pull/1760 ) )
9
11
- Added ` aio_writev ` and ` aio_readv ` .
10
12
(#[ 1713] ( https://github.com/nix-rust/nix/pull/1713 ) )
11
-
12
13
- impl ` From<uid_t> ` for ` Uid ` and ` From<gid_t> ` for ` Gid `
13
14
(#[ 1727] ( https://github.com/nix-rust/nix/pull/1727 ) )
14
15
- impl From<SockaddrIn > for std::net::SocketAddrV4 and
Original file line number Diff line number Diff line change @@ -330,6 +330,15 @@ impl TimeValLike for TimeSpec {
330
330
}
331
331
332
332
impl TimeSpec {
333
+ /// Construct a new `TimeSpec` from its components
334
+ #[ cfg_attr( target_env = "musl" , allow( deprecated) ) ] // https://github.com/rust-lang/libc/issues/1848
335
+ pub const fn new ( seconds : time_t , nanoseconds : timespec_tv_nsec_t ) -> Self {
336
+ Self ( timespec {
337
+ tv_sec : seconds,
338
+ tv_nsec : nanoseconds,
339
+ } )
340
+ }
341
+
333
342
fn nanos_mod_sec ( & self ) -> timespec_tv_nsec_t {
334
343
if self . tv_sec ( ) < 0 && self . tv_nsec ( ) > 0 {
335
344
self . tv_nsec ( ) - NANOS_PER_SEC as timespec_tv_nsec_t
@@ -564,6 +573,15 @@ impl TimeValLike for TimeVal {
564
573
}
565
574
566
575
impl TimeVal {
576
+ /// Construct a new `TimeVal` from its components
577
+ #[ cfg_attr( target_env = "musl" , allow( deprecated) ) ] // https://github.com/rust-lang/libc/issues/1848
578
+ pub const fn new ( seconds : time_t , microseconds : suseconds_t ) -> Self {
579
+ Self ( timeval {
580
+ tv_sec : seconds,
581
+ tv_usec : microseconds,
582
+ } )
583
+ }
584
+
567
585
fn micros_mod_sec ( & self ) -> suseconds_t {
568
586
if self . tv_sec ( ) < 0 && self . tv_usec ( ) > 0 {
569
587
self . tv_usec ( ) - MICROS_PER_SEC as suseconds_t
You can’t perform that action at this time.
0 commit comments