use idgen_rs::{snowflake_init, id_helper};
#[cfg(feature = "encodings")]
use idgen_rs::{IdEncoding, IdDecoding};
use chrono::{DateTime, Local};
const WORKER_ID: u16 = 1;
fn main() {
snowflake_init(WORKER_ID);
println!("已初始化: {}", id_helper::is_initialized());
let new_id = id_helper::next_id();
println!("new_id: {}", new_id);
#[cfg(feature = "encodings")]
{
let encoded = new_id.to_base62();
println!("base62: {}", encoded);
let encoded = new_id.to_base64_url();
println!("base64 url: {}", encoded);
if let Ok(decoded) = u64::from_base62(&new_id.to_base62()) {
println!("base62 解码: {}", decoded);
}
if let Ok(decoded) = u64::from_base64_url(&new_id.to_base64_url()) {
println!("base64 url 解码: {}", decoded);
}
}
let ids = id_helper::next_ids(5);
println!("批量生成: {:?}", ids);
let info = id_helper::extract_id_info(new_id);
println!("ID 信息: worker_id={}, sequence={}", info.worker_id, info.sequence);
let datetime: DateTime<Local> = info.system_time.into();
println!("time: {}", datetime.format("%Y-%m-%d %H:%M:%S"));
if let Some(utc_time) = id_helper::extract_time_utc(new_id) {
println!("UTC time: {}", utc_time.format("%Y-%m-%d %H:%M:%S UTC"));
}
}