tokio-rs / io-uring

The `io_uring` library for Rust
Apache License 2.0
1.19k stars 131 forks source link

add conversions between Timespec and Duration #222

Closed FrankReh closed 1 year ago

FrankReh commented 1 year ago

Like the nix crate does:

On Linux, the std::time::Duration and __kernel_timespec should be trivially interchangeable.

This implements the std::convert::From trait in each direction.

FrankReh commented 1 year ago

I'm assuming you would know that the compiler will optimize the TimeSpec sequence of calls

types::Timespec::new().sec(dur.as_secs()).nsec(dur.subsec_nanos())

because I myself am not sure. So I don't think my From impl's actually add any value. I realize there is no reason to convert back from a TimeSpec to a Duration. So I'm going to close this. Thanks for considering it though.