#[repr(C)]pub struct Timespec {
pub tv_sec: Secs,
pub tv_nsec: Nsecs,
}Available on crate feature
event and (crate feature event, or crate feature fs, or crate feature process, or crate feature runtime, or crate feature thread, or crate feature time, or linux_raw and non-crate feature use-explicitly-provided-auxv and non-crate feature use-libc-auxv and (x86 or crate feature param or crate feature process or crate feature runtime or crate feature time), or crate feature event and (bsd or linux_kernel or WASI or Windows)) only.Expand description
struct timespec—A quantity of time in seconds plus nanoseconds.
Fields§
§tv_sec: SecsSeconds.
tv_nsec: NsecsNanoseconds. Must be less than 1_000_000_000.
When passed to rustix::fs::utimensat, this field may instead be
assigned the values UTIME_NOW or UTIME_OMIT.
Implementations§
Source§impl Timespec
impl Timespec
Sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Checked Timespec addition. Returns None if overflow occurred.
§Panics
If 0 <= .tv_nsec < 1_000_000_000 doesn’t hold, this function may
panic or return unexpected results.
§Example
use rustix::event::Timespec;
assert_eq!(
Timespec {
tv_sec: 1,
tv_nsec: 2
}
.checked_add(Timespec {
tv_sec: 30,
tv_nsec: 40
}),
Some(Timespec {
tv_sec: 31,
tv_nsec: 42
})
);
assert_eq!(
Timespec {
tv_sec: 0,
tv_nsec: 999_999_999
}
.checked_add(Timespec {
tv_sec: 0,
tv_nsec: 2
}),
Some(Timespec {
tv_sec: 1,
tv_nsec: 1
})
);
assert_eq!(
Timespec {
tv_sec: i64::MAX,
tv_nsec: 999_999_999
}
.checked_add(Timespec {
tv_sec: 0,
tv_nsec: 1
}),
None
);Sourcepub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
Checked Timespec subtraction. Returns None if overflow occurred.
§Panics
If 0 <= .tv_nsec < 1_000_000_000 doesn’t hold, this function may
panic or return unexpected results.
§Example
use rustix::event::Timespec;
assert_eq!(
Timespec {
tv_sec: 31,
tv_nsec: 42
}
.checked_sub(Timespec {
tv_sec: 30,
tv_nsec: 40
}),
Some(Timespec {
tv_sec: 1,
tv_nsec: 2
})
);
assert_eq!(
Timespec {
tv_sec: 1,
tv_nsec: 1
}
.checked_sub(Timespec {
tv_sec: 0,
tv_nsec: 2
}),
Some(Timespec {
tv_sec: 0,
tv_nsec: 999_999_999
})
);
assert_eq!(
Timespec {
tv_sec: i64::MIN,
tv_nsec: 0
}
.checked_sub(Timespec {
tv_sec: 0,
tv_nsec: 1
}),
None
);Trait Implementations§
Source§impl AddAssign for Timespec
impl AddAssign for Timespec
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+= operation. Read moreimpl Copy for Timespec
impl Eq for Timespec
Source§impl Ord for Timespec
impl Ord for Timespec
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for Timespec
impl PartialOrd for Timespec
impl StructuralPartialEq for Timespec
Source§impl SubAssign for Timespec
impl SubAssign for Timespec
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-= operation. Read moreAuto Trait Implementations§
impl Freeze for Timespec
impl RefUnwindSafe for Timespec
impl Send for Timespec
impl Sync for Timespec
impl Unpin for Timespec
impl UnsafeUnpin for Timespec
impl UnwindSafe for Timespec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more