use std::sync::{Mutex, OnceLock};
use uuid::Uuid;
pub struct GeneratorId;
static SNOWFLAKE_BUCKET: OnceLock<Mutex<snowflake::SnowflakeIdBucket>> = OnceLock::new();
fn get_snowflake_bucket() -> &'static Mutex<snowflake::SnowflakeIdBucket> {
SNOWFLAKE_BUCKET.get_or_init(|| Mutex::new(snowflake::SnowflakeIdBucket::new(1, 1)))
}
impl GeneratorId {
pub fn uuid_v4() -> String {
Uuid::new_v4().as_simple().to_string()
}
pub fn uuid_v4_12() -> String {
let uuid = Uuid::new_v4().to_string().replace("-","");
uuid[0..12].to_string()
}
pub fn snowflake_id() -> i64 {
let mut bucket = get_snowflake_bucket().lock().unwrap();
bucket.get_id()
}
}