跳到主要内容

Instant

搜索

结构体 Instant 

Source
pub struct Instant(/* private fields */);
展开描述

单调递增时钟的测量值。 不透明,只能与 Duration 配合使用。

所得的时长是真实时长,不受时钟调整、 闰秒等影响。 若需获取挂钟时间,请改用 Date

实现§

Source§

impl Instant

Source

pub fn now() -> Instant

返回对应“现在”的时刻

此函数同时会更新已存储的时刻。

Source

pub fn now_without_cache_update() -> Instant

返回对应“现在”的时刻,且不更新缓存值。

调用后,recent() 仍会返回旧的时刻。

通常应优先使用 now() 而非此函数。

Source

pub fn recent() -> Instant

返回最近一次更新对应的时刻

Source

pub fn update()

更新已存储的时刻

应当频繁调用此函数,例如在事件循环中或使用 Updater 任务。

Source

pub fn duration_since(&self, earlier: Instant) -> Duration

返回从另一时刻到此刻所经过的时间长度

Source

pub fn elapsed_since_recent(&self) -> Duration

返回从该时刻创建到最近一次更新之间所经过的时间长度

Source

pub fn elapsed(&self) -> Duration

返回自该时刻创建以来所经过的时间长度

此函数同时会更新已存储的时刻。

Source

pub const fn as_ticks(&self) -> u64

以“刻度数”形式返回该时刻的表示。

请注意,一个‘刻度’的长度并不保证在不同平台上, 或在不同 coarsetime 版本之间 代表相同的时间长度。

还需注意,由“0”刻度表示的时刻是未定义的, 并不保证在不同平台上或不同 coarsetime 版本之间 代表同一时间。

本 API 主要用于需要将 Instant 的值存储到 AtomicU64 中的场景。

Source

pub const fn from_ticks(ticks: u64) -> Instant

以指定的“刻度数”创建一个 Instant

请注意,一个‘刻度’的长度并不保证在不同平台上, 或在不同 coarsetime 版本之间 代表相同的时间长度。

还需注意,由“0”刻度表示的时刻是未定义的, 并不保证在不同平台上或不同 coarsetime 版本之间 代表同一时间。

Source

pub const fn saturating_add(self, rhs: Duration) -> Instant

计算一个晚于当前 Instant 一个 Duration 的时刻,溢出时饱和

Source

pub fn checked_add(self, rhs: Duration) -> Option<Instant>

计算一个晚于当前 Instant 一个 Duration 的时刻,溢出时返回 None

Source

pub const fn saturating_sub(self, rhs: Duration) -> Instant

计算一个早于当前 Instant 一个 Duration 的时刻,下溢时饱和

Source

pub fn checked_sub(self, rhs: Duration) -> Option<Instant>

计算一个早于当前 Instant 一个 Duration 的时刻,下溢时返回 None

Trait 实现§

Source§

impl Add<Duration> for Instant

Source§

type Output = Instant

应用 + 运算符后得到的类型。
Source§

fn add(self, rhs: Duration) -> Instant

Performs the + operation. 更多信息
Source§

impl AddAssign<Duration> for Instant

Source§

fn add_assign(&mut self, rhs: Duration)

Performs the += operation. 更多信息
Source§

impl Clone for Instant

Source§

fn clone(&self) -> Instant

返回值的副本。 更多信息
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 更多信息
Source§

impl Debug for Instant

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

使用给定的格式化器格式化此值。 更多信息
Source§

impl Default for Instant

Source§

fn default() -> Instant

Returns the “default value” for a type. 更多信息
Source§

impl Hash for Instant

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. 更多信息
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. 更多信息
Source§

impl Ord for Instant

Source§

fn cmp(&self, other: &Instant) -> Ordering

This method returns an Ordering between self and other. 更多信息
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. 更多信息
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. 更多信息
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. 更多信息
Source§

impl PartialEq for Instant

Source§

fn eq(&self, other: &Instant) -> bool

测试 selfother 值是否相等,供 == 运算符使用。
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

测试 != 运算符。默认实现几乎总是够用,除非有非常充分的理由,否则不应被覆盖。
Source§

impl PartialOrd for Instant

Source§

fn partial_cmp(&self, other: &Instant) -> Option<Ordering>

若存在,此方法返回 selfother 值之间的排序关系。 更多信息
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

测试小于(针对 selfother),供 < 运算符使用。 更多信息
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. 更多信息
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. 更多信息
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. 更多信息
Source§

impl Sub<Duration> for Instant

Source§

type Output = Instant

应用 - 运算符后得到的类型。
Source§

fn sub(self, rhs: Duration) -> Instant

Performs the - operation. 更多信息
Source§

impl Sub for Instant

Source§

type Output = Duration

应用 - 运算符后得到的类型。
Source§

fn sub(self, other: Instant) -> Duration

Performs the - operation. 更多信息
Source§

impl SubAssign<Duration> for Instant

Source§

fn sub_assign(&mut self, rhs: Duration)

Performs the -= operation. 更多信息
Source§

impl Copy for Instant

Source§

impl Eq for Instant

Source§

impl StructuralPartialEq for Instant

自动 Trait 实现§

Blanket 实现§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. 更多信息
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. 更多信息
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 更多信息
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 更多信息
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

原样返回传入的参数。

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

调用 U::from(self)

That is, this conversion is whatever the implementation of From<T> for U 的实现方式。

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

获得所有权后的类型。
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. 更多信息
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 更多信息
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

转换出错时返回的类型。
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

执行转换。
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

转换出错时返回的类型。
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

执行转换。