1
0
mirror of synced 2026-02-10 15:07:57 +08:00
Files
SnowFlake-IdGenerator/Rust/source/src/lib.rs
2021-04-06 00:27:05 +08:00

38 lines
949 B
Rust

mod idgen;
#[macro_use]
// extern crate lazy_static;
extern crate libc;
use libc::{c_char, uint32_t};
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(workerId: u32, workerIdBitLength: u8, seqBitLength: u8) {
let mut options = IdGeneratorOptions::New(1);
options.WorkerIdBitLength = workerIdBitLength;
options.SeqBitLength = seqBitLength;
YitIdHelper::SetIdGenerator(options);
}
#[no_mangle]
pub extern "C" fn SetWorkerId(workerId: u32) {
YitIdHelper::SetWorkerId(workerId);
}
#[no_mangle]
pub extern "C" fn NextId() -> i64 {
YitIdHelper::NextId()
}
// build-win-x64: cargo build --release
// build-linux-x64: cargo build --target x86_64-unknown-linux-musl --release