devela/sys/os/linux/structs/
timespec.rs
1#![cfg_attr(not(feature = "unsafe_syscall"), allow(dead_code))]
4
5use crate::Duration;
6
7#[derive(Clone, Copy, Debug, Default, PartialEq)]
12#[repr(C)]
13pub struct LinuxTimespec {
14 pub tv_sec: isize,
16 pub tv_nsec: isize,
18}
19
20impl LinuxTimespec {
21 #[must_use]
23 pub const fn new(seconds: isize, nanoseconds: isize) -> Self {
24 Self { tv_sec: seconds, tv_nsec: nanoseconds }
25 }
26
27 #[must_use]
29 pub const fn with(duration: Duration) -> Self {
30 Self {
31 tv_sec: duration.as_secs() as isize,
32 tv_nsec: duration.subsec_nanos() as isize,
33 }
34 }
35
36 #[must_use]
38 pub const fn as_ptr(&self) -> *const Self {
39 self as *const Self
40 }
41
42 #[must_use]
44 pub fn as_mut_ptr(&mut self) -> *mut Self {
45 self as *mut Self
46 }
47}
48
49impl From<Duration> for LinuxTimespec {
50 #[must_use]
51 fn from(duration: Duration) -> Self {
52 Self::with(duration)
53 }
54}