pub struct Instant(/* private fields */);展开描述
单调递增时钟的测量值。
不透明,只能与 Duration 配合使用。
所得的时长是真实时长,不受时钟调整、
闰秒等影响。
若需获取挂钟时间,请改用 Date。
实现§
Source§impl Instant
impl Instant
Sourcepub fn now_without_cache_update() -> Instant
pub fn now_without_cache_update() -> Instant
返回对应“现在”的时刻,且不更新缓存值。
调用后,recent() 仍会返回旧的时刻。
通常应优先使用 now() 而非此函数。
Sourcepub fn duration_since(&self, earlier: Instant) -> Duration
pub fn duration_since(&self, earlier: Instant) -> Duration
返回从另一时刻到此刻所经过的时间长度
Sourcepub fn elapsed_since_recent(&self) -> Duration
pub fn elapsed_since_recent(&self) -> Duration
返回从该时刻创建到最近一次更新之间所经过的时间长度
Sourcepub const fn as_ticks(&self) -> u64
pub const fn as_ticks(&self) -> u64
以“刻度数”形式返回该时刻的表示。
请注意,一个‘刻度’的长度并不保证在不同平台上,
或在不同 coarsetime 版本之间
代表相同的时间长度。
还需注意,由“0”刻度表示的时刻是未定义的,
并不保证在不同平台上或不同 coarsetime 版本之间
代表同一时间。
本 API 主要用于需要将 Instant 的值存储到
AtomicU64 中的场景。
Sourcepub const fn from_ticks(ticks: u64) -> Instant
pub const fn from_ticks(ticks: u64) -> Instant
以指定的“刻度数”创建一个 Instant。
请注意,一个‘刻度’的长度并不保证在不同平台上,
或在不同 coarsetime 版本之间
代表相同的时间长度。
还需注意,由“0”刻度表示的时刻是未定义的,
并不保证在不同平台上或不同 coarsetime 版本之间
代表同一时间。
Sourcepub const fn saturating_add(self, rhs: Duration) -> Instant
pub const fn saturating_add(self, rhs: Duration) -> Instant
计算一个晚于当前 Instant 一个 Duration 的时刻,溢出时饱和
Sourcepub fn checked_add(self, rhs: Duration) -> Option<Instant>
pub fn checked_add(self, rhs: Duration) -> Option<Instant>
计算一个晚于当前 Instant 一个 Duration 的时刻,溢出时返回 None
Sourcepub const fn saturating_sub(self, rhs: Duration) -> Instant
pub const fn saturating_sub(self, rhs: Duration) -> Instant
计算一个早于当前 Instant 一个 Duration 的时刻,下溢时饱和
Sourcepub fn checked_sub(self, rhs: Duration) -> Option<Instant>
pub fn checked_sub(self, rhs: Duration) -> Option<Instant>
计算一个早于当前 Instant 一个 Duration 的时刻,下溢时返回 None
Trait 实现§
Source§impl AddAssign<Duration> for Instant
impl AddAssign<Duration> for Instant
Source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
Performs the
+= operation. 更多信息Source§impl Ord for Instant
impl Ord for Instant
Source§impl PartialOrd for Instant
impl PartialOrd for Instant
Source§impl SubAssign<Duration> for Instant
impl SubAssign<Duration> for Instant
Source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
Performs the
-= operation. 更多信息impl Copy for Instant
impl Eq for Instant
impl StructuralPartialEq for Instant
自动 Trait 实现§
impl Freeze for Instant
impl RefUnwindSafe for Instant
impl Send for Instant
impl Sync for Instant
impl Unpin for Instant
impl UnsafeUnpin for Instant
impl UnwindSafe for Instant
Blanket 实现§
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. 更多信息