auto commit
This commit is contained in:
2
Rust/source/Cargo.lock
generated
2
Rust/source/Cargo.lock
generated
@@ -269,7 +269,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "yitidgen"
|
||||
name = "yiter-idgenerator"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
[package]
|
||||
name = "yitidgen"
|
||||
name = "yiter-idgenerator"
|
||||
version = "1.0.0"
|
||||
authors = ["yitter <yitter@126.com>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
description="Shorter ID and faster generation with a new snowflake drift algorithm. The core is to shorten the ID length, but also can have a very high instantaneous concurrent processing capacity (50W/0.1s), and powerful configuration capacity."
|
||||
readme = "README.md"
|
||||
homepage ="https://github.com/yitter/IdGenerator"
|
||||
repository = "https://github.com/yitter/IdGenerator"
|
||||
keywords = ["snowflake", "idgenerator"]
|
||||
#categories = ["command-line-utilities"]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@@ -11,7 +18,7 @@ chrono = "0.4.10"
|
||||
lazy_static = "1.4.0"
|
||||
#simple_redis = "*"
|
||||
redis = "0.20.0"
|
||||
libc="*"
|
||||
libc = "*"
|
||||
|
||||
#actix = "0.9.0"
|
||||
#actix-web = "2.0"
|
||||
|
||||
23
Rust/source/README.md
Normal file
23
Rust/source/README.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# idgenerator
|
||||
|
||||
## 调用示例(Rust)
|
||||
|
||||
第1步,**全局** 初始化(应用程序启动时执行一次):
|
||||
```
|
||||
// 创建 IdGeneratorOptions 对象,请在构造函数中输入 WorkerId:
|
||||
let mut options = IdGeneratorOptions::New(1);
|
||||
// options.WorkerIdBitLength = 10; // WorkerIdBitLength 默认值6,支持的 WorkerId 最大值为2^6-1,若 WorkerId 超过64,可设置更大的 WorkerIdBitLength
|
||||
// ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。
|
||||
|
||||
// 保存参数(必须的操作,否则以上设置都不能生效):
|
||||
YitIdHelper::SetIdGenerator(options);
|
||||
// 以上初始化过程只需全局一次,且必须在第2步之前设置。
|
||||
```
|
||||
|
||||
第2步,生成ID:
|
||||
```
|
||||
// 初始化以后,即可在任何需要生成ID的地方,调用以下方法:
|
||||
long newId = YitIdHelper::NextId();
|
||||
```
|
||||
|
||||
|
||||
@@ -14,17 +14,17 @@ use libc::{c_char, uint32_t};
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::str;
|
||||
|
||||
lazy_static! {
|
||||
//static ref TestValue: Vec<i32> = vec!(0);
|
||||
// static ref MAP: HashMap<u32, String> = HashMap::new();
|
||||
}
|
||||
// lazy_static! {
|
||||
// static ref TestValue: Vec<i32> = vec!(0);
|
||||
// static ref MAP: HashMap<u32, String> = HashMap::new();
|
||||
// }
|
||||
|
||||
|
||||
// // #[export_name = "SetIdGenerator"]
|
||||
// #[no_mangle]
|
||||
// pub extern "C" fn SetIdGenerator(options: IdGeneratorOptions) {
|
||||
// YitIdHelper::SetIdGenerator(options);
|
||||
// }
|
||||
// #[export_name = "SetIdGenerator"]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn SetIdGenerator(options: IdGeneratorOptions) {
|
||||
YitIdHelper::SetIdGenerator(options);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn SetOptions(workerId: u32, workerIdBitLength: u8, seqBitLength: u8) {
|
||||
|
||||
Reference in New Issue
Block a user