Struct fastsend::TimeSerialer[][src]

pub struct TimeSerialer(_);
Expand description

TimeSerialer 是基于时间的序列号生成器,该序列号由纯数字组成,其特点在于可以从序列号一眼看出生成的 时间节 点(精确到秒)。

该序列号生成器采用了类似全局变量的方式来解决序列号冲突的问题,其构造了一个全局 slot 用于存储短时间内生成的序列 号,该 slot 的实现方式为 HashMap,并使用了全局读写锁,新产生的序列号将先在该 slot 中查询是否已被创建过(是否 冲突),只有在非冲突的场合下才会完成序列号生成。

TimeSerialer 具有对全局 slot 的定时清理功能,当 slot 存储的序列号超过一定阈值时会触发清理任务,将在额外的 线程完成对 slot 的清理,最早时间节点创建的序列号将从 slot 中丢弃,因为它们(指这些被丢弃的序列号)已经被证实不 会再次出现。

Implementations

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Output 是代表序列号的类型,其应实现 Display trait,这也意味着序列号能通过 ToString trait 转化为 String 类型。 Read more

build 方法类似于 Hasher::finish 方法,消耗自身构建出序列号,值得注意的是,在许多场景下, 构建序列号的方式会依赖外部系统,因此在设计 build 的 API 时,考虑到调用外部系统往往需要使用 Future 来支持异步任务,在返回值的设计上选择了 Pin<Box<dyn Future>> 来提供对 async/await 的支持(这也是在当前 Rust 版本下,语法层面不支持 async-trait 的一种妥协方案)。 Read more

feed 用于向 Serialer 提供用于生成序列号的必要信息,类似于 Hasher trait 中的 write 方法。

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.