### Any Trait Implementation for DefaultIdGenerator Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.DefaultIdGenerator.html Implements the Any trait, providing a type_id method to get the TypeId of the instance. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Type ID Implementation Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.IdGeneratorOptions.html Provides a method to get the TypeId of an instance, useful for runtime type identification. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Get Next Time Tick Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/snow_worker_m1.rs.html Retrieves the next available time tick for ID generation. If the current time tick is not greater than the last recorded time tick, it pauses for 1ms and retries until a new time tick is available. This ensures monotonically increasing timestamps for generated IDs. ```rust fn GetNextTimeTick(&self) -> i64 { let mut tempTimeTicker = self.GetCurrentTimeTick(); while tempTimeTicker <= self._LastTimeTick { // 暂停1ms sleep(std::time::Duration::from_millis(1)); tempTimeTicker = self.GetCurrentTimeTick(); } tempTimeTicker } ``` -------------------------------- ### Get Current Time Tick Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/snow_worker_m1.rs.html Retrieves the current time in milliseconds since the base time, used for ID generation. ```rust fn GetCurrentTimeTick(&self) -> i64 { return Utc::now().timestamp_millis() - self.BaseTime; } ``` -------------------------------- ### Build Commands for yit_id_generator Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/lib.rs.html Commands to build the yit_id_generator project for Windows and Linux. ```bash build-win-x64: cargo build --release build-linux-x64: cargo build --target x86_64-unknown-linux-musl --release ``` -------------------------------- ### From Implementation Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.IdGeneratorOptions.html Enables creating an instance of a type from itself, a trivial conversion. ```rust fn from(t: T) -> T ``` -------------------------------- ### Into Implementation Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.IdGeneratorOptions.html Allows converting an instance into another type that implements the From trait for the source type. ```rust fn into(self) -> U ``` -------------------------------- ### TryFrom Implementation Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.IdGeneratorOptions.html Provides a fallible conversion from one type to another, returning a Result. ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### TryInto Implementation Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.IdGeneratorOptions.html Provides a fallible conversion from one type into another, returning a Result. ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### impl Any for T Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Provides dynamic type information for any type T that is 'static and sized. ```rust impl Any for T where T: 'static + ?Sized, ``` -------------------------------- ### Borrow Implementation Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.IdGeneratorOptions.html Allows an instance to be borrowed immutably, enabling access to its data without taking ownership. ```rust fn borrow(&self) -> &T ``` -------------------------------- ### Initialize Snowflake Worker M1 Options Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/snow_worker_m1.rs.html Sets the initial options for the Snowflake worker, including various counters and flags for ID generation. ```rust let options = SnowFlakeM1Options { _LastTimeTick: 0, _TurnBackTimeTick: 0, _TurnBackIndex: 0, _IsOverCost: false, _OverCostCountInOneTerm: 0, _GenCountInOneTerm: 0, _TermIndex: 0, }; worker.SetOptions(options); worker ``` -------------------------------- ### New IdGeneratorOptions Constructor Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/id_generator_options.rs.html Provides a constructor for creating a new `IdGeneratorOptions` instance with default values, requiring only the `workerId` to be specified. This is useful for initializing the generator with standard settings. ```rust impl IdGeneratorOptions { #[allow(non_snake_case)] pub fn New(workerId: u32) -> IdGeneratorOptions { IdGeneratorOptions { Method: 1, WorkerId: workerId, BaseTime: 1582136402000, WorkerIdBitLength: 6, SeqBitLength: 6, MaxSeqNumber: 0, MinSeqNumber: 5, TopOverCostCount: 2000, } } } ``` -------------------------------- ### DefaultIdGenerator Constructor Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.DefaultIdGenerator.html Provides a default constructor for creating a new DefaultIdGenerator instance. ```rust pub fn Default() -> DefaultIdGenerator ``` -------------------------------- ### SetOptions Function Signature Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/fn.SetOptions.html The external C-compatible function signature for `SetOptions`. It takes the worker ID bit length and sequence bit length as parameters to configure the ID generation process. ```rust #[unsafe(no_mangle)] pub extern "C" fn SetOptions( _worker_id: u32, worker_id_bit_length: u8, seq_bit_length: u8, ) ``` -------------------------------- ### BorrowMut Implementation Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.IdGeneratorOptions.html Allows an instance to be borrowed mutably, enabling modification of its data. ```rust fn borrow_mut(&mut self) -> &mut T ``` -------------------------------- ### SetOptions Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/lib.rs.html Configures the ID generator with worker ID bit length and sequence bit length. It internally calls `SetIdGenerator`. ```APIDOC ## SetOptions ### Description Configures the ID generator by specifying the bit lengths for worker ID and sequence number. A default worker ID of 1 is used if not otherwise specified. ### Signature `pub extern "C" fn SetOptions(_worker_id: u32, worker_id_bit_length: u8, seq_bit_length: u8)` ### Parameters * **_worker_id** (`u32`) - This parameter is currently unused but present for potential future use. * **worker_id_bit_length** (`u8`) - The number of bits to allocate for the worker ID. * **seq_bit_length** (`u8`) - The number of bits to allocate for the sequence number. ``` -------------------------------- ### NextId Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/lib.rs.html Generates and returns the next unique ID based on the current configuration. ```APIDOC ## NextId ### Description Generates and returns the next unique 64-bit integer ID. ### Signature `pub extern "C" fn NextId() -> i64` ### Returns * **i64** - The next generated unique ID. ``` -------------------------------- ### impl TryFrom for T Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Allows attempting to convert a type U into a type T, which may fail. ```rust impl TryFrom for T where U: Into, ``` -------------------------------- ### impl TryInto for T Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Allows attempting to convert a type T into a type U, which may fail. ```rust impl TryInto for T where U: TryFrom, ``` -------------------------------- ### Module Imports and Re-exports Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/mod.rs.html Shows the main imports and re-exports for the idgen module, including different SnowWorker implementations and configuration options. ```rust 1mod default_id_generator; 2mod yit_id_helper; 3mod snow_worker_m1; 4mod snow_worker_m2; 5mod id_generator_options; 6mod i_snow_worker; 7mod over_cost_action_arg; 8 9use snow_worker_m1::SnowWorkerM1; 10//use snow_worker_m2::SnowWorkerM2; 11 12pub use over_cost_action_arg::OverCostActionArg; 13pub use yit_id_helper::YitIdHelper; 14pub use default_id_generator::DefaultIdGenerator; 15pub use id_generator_options::IdGeneratorOptions; 16pub use i_snow_worker::ISnowWorker; 17 18 ``` -------------------------------- ### New IdGeneratorOptions Function Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.IdGeneratorOptions.html A constructor function to create a new IdGeneratorOptions instance with a specified worker ID. ```rust pub fn New(workerId: u32) -> IdGeneratorOptions ``` -------------------------------- ### NextId Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/fn.NextId.html The NextId function is an external C function that returns a 64-bit integer. It is marked as unsafe and has no mangling, indicating it's intended for C interop. ```APIDOC ## Function NextId ### Description Generates and returns a unique 64-bit integer ID. ### Signature ```rust #[unsafe(no_mangle)] pub extern "C" fn NextId() -> i64 ``` ### Return Value - `i64`: A 64-bit integer representing the generated ID. ``` -------------------------------- ### YitIdHelper Implementation Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/yit_id_helper.rs.html This snippet shows the core implementation of the YitIdHelper struct in Rust. It utilizes `OnceLock` for thread-safe lazy initialization of the `DefaultIdGenerator` and provides methods for setting generator options and generating unique IDs. ```rust 1/* 2 * 版权属于:yitter(yitter@126.com) 3 * 开源地址:https://github.com/yitter/idgenerator 4 */ 5use std::sync::{Mutex, OnceLock}; 6use std::sync::Arc; 7use crate::idgen::*; 8 9pub struct YitIdHelper; 10 11//static mut idGenInstance: Option>> = None; 12static ID_GEN_INSTANCE: OnceLock>> = OnceLock::new(); 13#[allow(non_snake_case)] 14impl YitIdHelper { 15 fn IdGenInstance() -> Arc> { 16 ID_GEN_INSTANCE 17 .get_or_init(|| Arc::new(Mutex::new(DefaultIdGenerator::Default()))) 18 .clone() 19 } 20 21 pub fn SetIdGenerator(options: IdGeneratorOptions) { 22 let idgenArc = YitIdHelper::IdGenInstance(); 23 let mut idgen = idgenArc.lock().unwrap(); 24 idgen.Worker.SetOptions(options); 25 } 26 #[allow(dead_code)] 27 pub fn SetWorkerId(workerId: u32) { 28 let idgenArc = YitIdHelper::IdGenInstance(); 29 let mut idgen = idgenArc.lock().unwrap(); 30 let options = IdGeneratorOptions::New(workerId); 31 idgen.Worker.SetOptions(options); 32 } 33 34 pub fn NextId() -> i64 { 35 let idgenArc = YitIdHelper::IdGenInstance(); 36 let mut idgen = idgenArc.lock().unwrap(); 37 idgen.Worker.NextId() 38 } 39} ``` -------------------------------- ### Rust Library Functions for ID Generation Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/lib.rs.html Exposes functions for setting ID generator options, worker IDs, and generating the next ID. These functions are intended for C interop. ```rust mod idgen; //#[macro_use] // extern crate lazy_static; extern crate libc; //use std::ffi::{CStr, CString}; //use std::str; pub use idgen::*; // #[export_name = "SetIdGenerator"] #[no_mangle] pub extern "C" fn SetIdGenerator(options: IdGeneratorOptions) { YitIdHelper::SetIdGenerator(options); } #[no_mangle] pub extern "C" fn SetOptions(_worker_id: u32, worker_id_bit_length: u8, seq_bit_length: u8) { let mut options = IdGeneratorOptions::New(1); options.WorkerIdBitLength = worker_id_bit_length; options.SeqBitLength = seq_bit_length; YitIdHelper::SetIdGenerator(options); } #[no_mangle] pub extern "C" fn SetWorkerId(worker_id: u32) { YitIdHelper::SetWorkerId(worker_id); } #[no_mangle] pub extern "C" fn NextId() -> i64 { YitIdHelper::NextId() } ``` -------------------------------- ### Handle Next ID During Normal Operation Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/snow_worker_m1.rs.html Generates the next ID under normal operating conditions, including logic for time rollback and sequence exhaustion. ```rust fn NextNormalId(&mut self) -> i64 { let currentTimeTick = self.GetCurrentTimeTick(); if currentTimeTick < self._LastTimeTick { if self._TurnBackTimeTick < 1 { self._TurnBackTimeTick = self._LastTimeTick - 1; self._TurnBackIndex += 1; // 每毫秒序列数的前5位是预留位,0用于手工新值,1-4是时间回拨次序 // 支持4次回拨次序(避免回拨重叠导致ID重复),可无限次回拨(次序循环使用)。 if self._TurnBackIndex > 4 { self._TurnBackIndex = 1; } self.BeginTurnBackAction(self._TurnBackTimeTick); } // thread::sleep(std::time::Duration::from_millis(1)); return self.CalcTurnBackId(self._TurnBackTimeTick); } // 时间追平时,_TurnBackTimeTick清零 if self._TurnBackTimeTick > 0 { self.EndTurnBackAction(self._TurnBackTimeTick); self._TurnBackTimeTick = 0; } if currentTimeTick > self._LastTimeTick { self._LastTimeTick = currentTimeTick; self._CurrentSeqNumber = self.MinSeqNumber; return self.CalcId(self._LastTimeTick); } if self._CurrentSeqNumber > self.MaxSeqNumber { self.BeginOverCostAction(currentTimeTick); self._TermIndex += 1; self._LastTimeTick += 1; self._CurrentSeqNumber = self.MinSeqNumber; self._IsOverCost = true; self._OverCostCountInOneTerm = 1; self._GenCountInOneTerm = 1; return self.CalcId(self._LastTimeTick); } self.CalcId(self._LastTimeTick) } ``` -------------------------------- ### DefaultIdGenerator Struct and Initialization Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/default_id_generator.rs.html Defines the DefaultIdGenerator struct and its default constructor. This struct wraps a SnowWorkerM1 instance. ```rust 1/* 2 * 版权属于:yitter(yitter@126.com) 3 * 开源地址:https://github.com/yitter/idgenerator 4 */ 5/*use std::{thread, time}; 6use std::net::UdpSocket; 7use chrono::Utc; 8use std::sync::Mutex; 9use std::sync::Arc; 10use std::borrow::BorrowMut;*/ 11use crate::idgen::*; 12// static mut instance2: Option>> = None; 13#[allow(non_snake_case)] 14pub struct DefaultIdGenerator { 15 pub Worker: SnowWorkerM1, 16} 17#[allow(non_snake_case)] 18impl DefaultIdGenerator { 19 pub fn Default() -> DefaultIdGenerator { 20 DefaultIdGenerator { Worker: SnowWorkerM1::Default() } 21 } 22} ``` -------------------------------- ### impl Borrow for T Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Allows borrowing a type T as a reference to T. ```rust impl Borrow for T where T: ?Sized, ``` -------------------------------- ### impl Sync for OverCostActionArg Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Indicates that OverCostActionArg can be safely shared between threads. ```rust impl Sync for OverCostActionArg ``` -------------------------------- ### impl Into for T Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Allows converting a type T into a type U, provided U implements From. ```rust impl Into for T where U: From, ``` -------------------------------- ### IdGeneratorOptions Struct Definition Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/id_generator_options.rs.html Defines the structure for configuring the Yitter ID generator. It includes fields for the generation method, base time, worker ID, and various bit lengths for worker ID and sequence numbers. It also specifies minimum and maximum sequence numbers and a count for top over-cost. ```rust /* * 版权属于:yitter(yitter@126.com) * 开源地址:https://github.com/yitter/idgenerator */ #[allow(non_snake_case)] #[repr(C)] pub struct IdGeneratorOptions { /// 雪花计算方法,(1-漂移算法|2-传统算法),默认1 pub Method: u8, /// 基础时间(ms单位),不能超过当前系统时间 pub BaseTime: i64, /// 必须由外部设定,最大值 2^WorkerIdBitLength-1 pub WorkerId: u32, /// 默认值6,取值范围 [1, 15](要求:序列数位长+机器码位长不超过22) pub WorkerIdBitLength: u8, /// 默认值6,取值范围 [3, 21](要求:序列数位长+机器码位长不超过22) pub SeqBitLength: u8, /// 设置范围 [MinSeqNumber, 2^SeqBitLength-1],默认值0,表示最大序列数取最大值(2^SeqBitLength-1] pub MaxSeqNumber: u32, /// 默认值5,取值范围 [5, MaxSeqNumber],每毫秒的前5个序列数对应编号0-4是保留位,其中1-4是时间回拨相应预留位,0是手工新值预留位 pub MinSeqNumber: u32, /// 最大漂移次数(含),默认2000,推荐范围 500-20000(与计算能力有关) pub TopOverCostCount: u32, } ``` -------------------------------- ### impl From for T Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Allows creating a value of type T from another value of the same type T. ```rust impl From for T ``` -------------------------------- ### Into Trait Implementation for DefaultIdGenerator Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.DefaultIdGenerator.html Implements the Into trait, enabling conversion to another type U if From for U is implemented. ```rust fn into(self) -> U ``` -------------------------------- ### IdGeneratorOptions Struct Definition Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.IdGeneratorOptions.html Defines the configuration options for the ID generator, including method, base time, worker ID, and bit lengths for worker ID and sequence numbers. ```rust #[repr(C)] pub struct IdGeneratorOptions { pub Method: u8, pub BaseTime: i64, pub WorkerId: u32, pub WorkerIdBitLength: u8, pub SeqBitLength: u8, pub MaxSeqNumber: u32, pub MinSeqNumber: u32, pub TopOverCostCount: u32, } ``` -------------------------------- ### Generate Next ID (Normal or Over-Cost) Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/snow_worker_m1.rs.html Determines whether to generate a normal ID or an ID during an over-cost situation based on the internal state. ```rust pub fn NextId(&mut self) -> i64 { // println!("SeqBitLength: {}", self.SeqBitLength); if self._IsOverCost { self.NextOverCostId() } else { self.NextNormalId() } } ``` -------------------------------- ### Handle Next ID During Over-Cost Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/snow_worker_m1.rs.html Generates the next ID when the system is in an over-cost state, handling time advancements and sequence resets. ```rust fn NextOverCostId(&mut self) -> i64 { let currentTimeTick = self.GetCurrentTimeTick(); if currentTimeTick > self._LastTimeTick { self.EndOverCostAction(currentTimeTick); self._LastTimeTick = currentTimeTick; self._CurrentSeqNumber = self.MinSeqNumber; self._IsOverCost = false; self._OverCostCountInOneTerm = 0; self._GenCountInOneTerm = 0; return self.CalcId(self._LastTimeTick); } if self._OverCostCountInOneTerm >= self.TopOverCostCount { self.EndOverCostAction(currentTimeTick); self._LastTimeTick = self.GetNextTimeTick(); self._CurrentSeqNumber = self.MinSeqNumber; self._IsOverCost = false; self._OverCostCountInOneTerm = 0; self._GenCountInOneTerm = 0; return self.CalcId(self._LastTimeTick); } if self._CurrentSeqNumber > self.MaxSeqNumber { self._LastTimeTick += 1; self._CurrentSeqNumber = self.MinSeqNumber; self._IsOverCost = true; self._OverCostCountInOneTerm += 1; self._GenCountInOneTerm += 1; return self.CalcId(self._LastTimeTick); } self._GenCountInOneTerm += 1; self.CalcId(self._LastTimeTick) } ``` -------------------------------- ### SetIdGenerator Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/lib.rs.html Sets the global configuration for the ID generator. This function should be called before generating any IDs. ```APIDOC ## SetIdGenerator ### Description Sets the global configuration for the ID generator using `IdGeneratorOptions`. ### Signature `pub extern "C" fn SetIdGenerator(options: IdGeneratorOptions)` ### Parameters * **options** (`IdGeneratorOptions`) - The configuration options for the ID generator. ``` -------------------------------- ### NextId Function Signature Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/fn.NextId.html The NextId function is declared as an unsafe extern "C" function that returns a 64-bit integer (i64). It is marked with #[unsafe(no_mangle)] to ensure predictable symbol naming for C linkage. ```rust #[unsafe(no_mangle)] pub extern "C" fn NextId() -> i64 ``` -------------------------------- ### impl Freeze for OverCostActionArg Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Indicates that OverCostActionArg can be safely frozen (its bits remain valid). ```rust impl Freeze for OverCostActionArg ``` -------------------------------- ### From Trait Implementation for DefaultIdGenerator Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.DefaultIdGenerator.html Implements the From trait, allowing conversion from a type T to itself. ```rust fn from(t: T) -> T ``` -------------------------------- ### impl BorrowMut for T Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Allows mutably borrowing a type T as a mutable reference to T. ```rust impl BorrowMut for T where T: ?Sized, ``` -------------------------------- ### impl UnwindSafe for OverCostActionArg Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Indicates that OverCostActionArg is safe to use across unwind boundaries. ```rust impl UnwindSafe for OverCostActionArg ``` -------------------------------- ### SetIdGenerator Function Signature Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/fn.SetIdGenerator.html The SetIdGenerator function is used to initialize or update the ID generator with specified options. It is marked as unsafe and has no mangling, indicating it's intended for C interop or specific low-level usage. ```APIDOC ## SetIdGenerator ### Description Initializes or updates the ID generator with the provided options. ### Signature ```rust #[unsafe(no_mangle)] pub extern "C" fn SetIdGenerator(options: IdGeneratorOptions) ``` ### Parameters * **options** (IdGeneratorOptions) - The configuration options for the ID generator. ``` -------------------------------- ### YitIdHelper::SetIdGenerator Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/yit_id_helper.rs.html Sets the configuration options for the ID generator. This method allows customization of the ID generation process based on provided options. ```APIDOC ## SetIdGenerator ### Description Sets the configuration options for the ID generator. This method allows customization of the ID generation process based on provided options. ### Method ``` pub fn SetIdGenerator(options: IdGeneratorOptions) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **options** (IdGeneratorOptions) - Required - The configuration options for the ID generator. ``` -------------------------------- ### DefaultIdGenerator Struct Definition Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.DefaultIdGenerator.html Defines the structure of DefaultIdGenerator, which includes a SnowWorkerM1 instance. ```rust pub struct DefaultIdGenerator { pub Worker: SnowWorkerM1, } ``` -------------------------------- ### SetIdGenerator Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.YitIdHelper.html Configures the ID generator with specified options. This method allows for customization of the ID generation process. ```APIDOC ## SetIdGenerator ### Description Configures the ID generator with specified options. This method allows for customization of the ID generation process. ### Method `pub fn SetIdGenerator(options: IdGeneratorOptions)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **options** (IdGeneratorOptions) - Required - The options to configure the ID generator. ``` -------------------------------- ### impl Send for OverCostActionArg Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Indicates that OverCostActionArg can be safely transferred between threads. ```rust impl Send for OverCostActionArg ``` -------------------------------- ### TryFrom Trait Implementation for DefaultIdGenerator Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.DefaultIdGenerator.html Implements the TryFrom trait for fallible conversion from type U to T. ```rust type Error = Infallible fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### SetWorkerId Function Signature Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/fn.SetWorkerId.html This is the external C function signature for SetWorkerId. It takes a u32 worker_id as input. It is marked as unsafe and not mangled. ```rust #[unsafe(no_mangle)] pub extern "C" fn SetWorkerId(worker_id: u32) ``` -------------------------------- ### SetIdGenerator Function Signature Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/fn.SetIdGenerator.html This is the external C function signature for SetIdGenerator. It takes IdGeneratorOptions as an argument and is marked with #[unsafe(no_mangle)] to ensure it can be called from C. ```rust #[unsafe(no_mangle)] pub extern "C" fn SetIdGenerator(options: IdGeneratorOptions) ``` -------------------------------- ### impl UnsafeUnpin for OverCostActionArg Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Indicates that OverCostActionArg is Unpin even if it contains types that are not. ```rust impl UnsafeUnpin for OverCostActionArg ``` -------------------------------- ### NextId Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.YitIdHelper.html Generates and returns the next unique ID. This method is thread-safe and suitable for concurrent access. ```APIDOC ## NextId ### Description Generates and returns the next unique ID. This method is thread-safe and suitable for concurrent access. ### Method `pub fn NextId() -> i64` ### Parameters None ### Response #### Success Response (200) - **id** (i64) - The generated unique ID. ``` -------------------------------- ### Borrow Trait Implementation for DefaultIdGenerator Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.DefaultIdGenerator.html Implements the Borrow trait, allowing immutable borrowing of the instance. ```rust fn borrow(&self) -> &T ``` -------------------------------- ### YitIdHelper::NextId Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/yit_id_helper.rs.html Generates and returns the next unique ID. This is the primary method for obtaining a new ID from the generator. ```APIDOC ## NextId ### Description Generates and returns the next unique ID. This is the primary method for obtaining a new ID from the generator. ### Method ``` pub fn NextId() -> i64 ``` ### Parameters None ### Response #### Success Response - **id** (i64) - The next generated unique ID. ``` -------------------------------- ### TryInto Trait Implementation for DefaultIdGenerator Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.DefaultIdGenerator.html Implements the TryInto trait for fallible conversion from type T to U. ```rust type Error = >::Error fn try_into(self) -> Result>::Error> ``` -------------------------------- ### impl Unpin for OverCostActionArg Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Indicates that OverCostActionArg does not require special handling for pinning. ```rust impl Unpin for OverCostActionArg ``` -------------------------------- ### type Error = >::Error Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Defines the error type for TryInto, which is the same as the error type for the corresponding TryFrom implementation. ```rust type Error = >::Error ``` -------------------------------- ### impl RefUnwindSafe for OverCostActionArg Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Indicates that OverCostActionArg is safe to use across unwind boundaries when borrowed. ```rust impl RefUnwindSafe for OverCostActionArg ``` -------------------------------- ### Calculate Normal ID Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/snow_worker_m1.rs.html Combines the current time tick, worker ID, and sequence number to form a unique ID. ```rust fn CalcId(&mut self, useTimeTick: i64) -> i64 { let result = (useTimeTick << self._TimestampShift) + (self.WorkerId << self.SeqBitLength) as i64 + (self._CurrentSeqNumber) as i64; self._CurrentSeqNumber += 1; result } ``` -------------------------------- ### BorrowMut Trait Implementation for DefaultIdGenerator Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.DefaultIdGenerator.html Implements the BorrowMut trait, allowing mutable borrowing of the instance. ```rust fn borrow_mut(&mut self) -> &mut T ``` -------------------------------- ### OverCostActionArg Struct Definition Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/over_cost_action_arg.rs.html Defines the structure for OverCostActionArg, used in ID generation to manage over-cost scenarios. Includes fields for action type, timestamps, worker identifiers, and counts within specific terms. ```rust 1/* 2 * 版权属于:yitter(yitter@126.com) 3 * 开源地址:https://github.com/yitter/idgenerator 4 */ 5#[allow(non_snake_case)] 6#[allow(dead_code)] 7pub struct OverCostActionArg { 8 ActionType: u32, 9 TimeTick: i64, 10 WorkerId: u16, 11 OverCostCountInOneTerm: i32, 12 GenCountInOneTerm: i32, 13 TermIndex: i32, 14} ``` -------------------------------- ### Calculate ID During Time Rollback Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/snow_worker_m1.rs.html Calculates a unique ID during a time rollback scenario, using a specific time tick and rollback index. ```rust fn CalcTurnBackId(&mut self, useTimeTick: i64) -> i64 { let result = (useTimeTick << self._TimestampShift) + (self.WorkerId << self.SeqBitLength) as i64 + (self._TurnBackIndex) as i64; self._TurnBackTimeTick -= 1; result } ``` -------------------------------- ### type Error = Infallible Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Defines the error type for TryFrom. Infallible means the conversion will not fail. ```rust type Error = Infallible ``` -------------------------------- ### ISnowWorker::NextId Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/trait.ISnowWorker.html The NextId method is a required function within the ISnowWorker trait. It is responsible for generating and returning a unique 64-bit integer ID. ```APIDOC ## fn NextId(&self) -> i64 ### Description Generates and returns a unique 64-bit integer ID. ### Signature ```rust fn NextId(&self) -> i64 ``` ### Returns A 64-bit signed integer representing the generated ID. ``` -------------------------------- ### YitIdHelper Struct Summary Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.YitIdHelper.html Defines the YitIdHelper struct, which is an empty struct used as a type marker for ID generation functionalities. ```rust pub struct YitIdHelper; ``` -------------------------------- ### OverCostActionArg Struct Definition Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.OverCostActionArg.html Defines the OverCostActionArg struct. It has private fields, indicating it's an internal type. ```rust pub struct OverCostActionArg { /* private fields */ } ``` -------------------------------- ### SetWorkerId Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/fn.SetWorkerId.html Sets the worker ID for the yit_id_generator. This function is unsafe and requires careful usage. ```APIDOC ## SetWorkerId ### Description Sets the worker ID for the yit_id_generator. This function is unsafe and requires careful usage. ### Signature ```rust #[unsafe(no_mangle)] pub extern "C" fn SetWorkerId(worker_id: u32) ``` ### Parameters #### Path Parameters - **worker_id** (u32) - Description: The worker ID to set. ``` -------------------------------- ### SetWorkerId Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/struct.YitIdHelper.html Sets the worker ID for the ID generator. This is crucial for distributed systems to ensure unique IDs across different workers. ```APIDOC ## SetWorkerId ### Description Sets the worker ID for the ID generator. This is crucial for distributed systems to ensure unique IDs across different workers. ### Method `pub fn SetWorkerId(workerId: u32)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **workerId** (u32) - Required - The unique identifier for the worker. ``` -------------------------------- ### ISnowWorker Trait Definition Source: https://docs.rs/yit_id_generator_main/1.0.1/yit_id_generator/trait.ISnowWorker.html Defines the ISnowWorker trait with a single required method, NextId. This trait is used for generating unique identifiers. ```rust pub trait ISnowWorker { // Required method fn NextId(&self) -> i64; } ``` -------------------------------- ### YitIdHelper::SetWorkerId Source: https://docs.rs/yit_id_generator_main/1.0.1/src/yit_id_generator/idgen/yit_id_helper.rs.html Sets the worker ID for the ID generator. This is a convenience method for setting a specific worker ID, which influences the generated IDs. ```APIDOC ## SetWorkerId ### Description Sets the worker ID for the ID generator. This is a convenience method for setting a specific worker ID, which influences the generated IDs. ### Method ``` #[allow(dead_code)] pub fn SetWorkerId(workerId: u32) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **workerId** (u32) - Required - The worker ID to set for the generator. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.