IdGeneratorOptions

Struct IdGeneratorOptions 

Source
pub struct IdGeneratorOptions {
    pub method: u8,
    pub base_time: i64,
    pub worker_id: u32,
    pub worker_id_bit_length: u8,
    pub seq_bit_length: u8,
    pub max_seq_number: u32,
    pub min_seq_number: u32,
    pub top_over_cost_count: u32,
    pub seq_step: u8,
}

Fields§

§method: u8

雪花计算方法,(1-漂移算法|2-传统算法),默认1

§base_time: i64

基础时间(ms单位),不能超过当前系统时间

§worker_id: u32

必须由外部设定,最大值 2^WorkerIdBitLength-1

§worker_id_bit_length: u8

默认值6,取值范围 [1, 15](要求:序列数位长+机器码位长不超过22)

§seq_bit_length: u8

默认值6,取值范围 [3, 21](要求:序列数位长+机器码位长不超过22)

§max_seq_number: u32

设置范围 [MinSeqNumber, 2^SeqBitLength-1],默认值0,表示最大序列数取最大值(2^SeqBitLength-1])

§min_seq_number: u32

默认值5,取值范围 [5, MaxSeqNumber],每毫秒的前5个序列数对应编号0-4是保留位,其中1-4是时间回拨相应预留位,0是手工新值预留位

§top_over_cost_count: u32

最大漂移次数(含),默认2000,推荐范围 500-20000(与计算能力有关)

§seq_step: u8

生成流水序列之间的步长,默认为1。

Implementations§

Source§

impl IdGeneratorOptions

Source

pub fn new(worker_id: u32) -> IdGeneratorOptions

创建新的生成器配置项,并赋予以下属性默认值:

  • method: 1。漂移算法。
  • base_time: 1582136402000。大约在2020219日。
  • worker_id_bit_length: 6。机器码占据6位。
  • seq_bit_length: 6。序列数占据6位。
  • max_seq_number: 0。
  • min_seq_number: 5。
  • top_over_cost_count: 2000。
  • seq_step: 1。自增长序列步长。
§Arguments
  • worker_id: 机器编号。

returns: IdGeneratorOptions

§Examples

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.