You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.1 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
2 years ago
2 years ago
2 years ago
4 years ago
2 years ago
4 years ago
2 years ago
4 years ago
4 years ago
4 years ago
2 years ago
4 years ago
4 years ago
4 years ago
1234567891011121314151617181920212223242526
  1. # ❄ idgenerator-Rust
  2. ## 调用示例(Rust)
  3. 第1步,**全局** 初始化(应用程序启动时执行一次):
  4. ```
  5. // 创建 IdGeneratorOptions 对象,可在构造函数中输入 WorkerId:
  6. let mut options = IdGeneratorOptions::New(Your_Unique_Worker_Id);
  7. // options.WorkerIdBitLength = 10; // 默认值6,限定 WorkerId 最大值为2^6-1,即默认最多支持64个节点。
  8. // options.SeqBitLength = 6; // 默认值6,限制每毫秒生成的ID个数。若生成速度超过5万个/秒,建议加大 SeqBitLength 到 10。
  9. // options.BaseTime = Your_Base_Time; // 如果要兼容老系统的雪花算法,此处应设置为老系统的BaseTime。
  10. // ...... 其它参数参考 IdGeneratorOptions 定义。
  11. // 保存参数(务必调用,否则参数设置不生效):
  12. YitIdHelper::SetIdGenerator(options);
  13. // 以上过程只需全局一次,且应在生成ID之前完成。
  14. ```
  15. 第2步,生成ID:
  16. ```
  17. // 初始化后,在任何需要生成ID的地方,调用以下方法:
  18. long newId = YitIdHelper::NextId();
  19. ```