#[repr(C)]pub struct Timespec {
pub tv_sec: Secs,
pub tv_nsec: Nsecs,
}
Available on crate feature
fs
only.Expand description
struct timespec
Fields§
§tv_sec: Secs
Seconds.
tv_nsec: Nsecs
Nanoseconds. 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 moreSource§impl Ord for Timespec
impl Ord for Timespec
Source§impl PartialOrd for Timespec
impl PartialOrd 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 moreimpl Copy for Timespec
impl Eq for Timespec
impl StructuralPartialEq for Timespec
Auto Trait Implementations§
impl Freeze for Timespec
impl RefUnwindSafe for Timespec
impl Send for Timespec
impl Sync for Timespec
impl Unpin 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