mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-06 01:58:46 +00:00
0d6b53bc3e
We want to keep the cast because tv_sec is not always 64 bits, see b5ff175b4
(Fix timer.rs cross-platform compilation, 2023-02-14).
It would be nice to avoid the clippy exemption, perhaps using something like
#[cfg(target_pointer_width = "32")]
let seconds = val.tv_sec as i64;
#[cfg(not(target_pointer_width = "32"))]
let seconds = val.tv_sec;
but I'm not sure if "target_pointer_width" is the right criteria.
24 lines
646 B
Rust
24 lines
646 B
Rust
//! Safe wrappers around various libc functions that we might want to reuse across modules.
|
|
|
|
use std::time::Duration;
|
|
|
|
#[allow(clippy::unnecessary_cast)]
|
|
pub const fn timeval_to_duration(val: &libc::timeval) -> Duration {
|
|
let micros = val.tv_sec as i64 * (1E6 as i64) + val.tv_usec as i64;
|
|
Duration::from_micros(micros as u64)
|
|
}
|
|
|
|
pub trait TimevalExt {
|
|
fn as_micros(&self) -> i64;
|
|
fn as_duration(&self) -> Duration;
|
|
}
|
|
|
|
impl TimevalExt for libc::timeval {
|
|
fn as_micros(&self) -> i64 {
|
|
timeval_to_duration(self).as_micros() as i64
|
|
}
|
|
|
|
fn as_duration(&self) -> Duration {
|
|
timeval_to_duration(self)
|
|
}
|
|
}
|