| Crates.io | bomboni_common |
| lib.rs | bomboni_common |
| version | 0.2.0 |
| created_at | 2023-11-14 03:18:45.318687+00 |
| updated_at | 2025-11-10 12:52:48.303492+00 |
| description | Common things for Bomboni library. |
| homepage | https://github.com/tinrab/bomboni |
| repository | https://github.com/tinrab/bomboni |
| max_upload_size | |
| id | 1034339 |
| size | 66,282 |
Common utilities for the Bomboni library.
This crate provides essential utilities for building distributed systems and applications.
use bomboni_common::id::{Id, worker::WorkerIdGenerator};
use std::str::FromStr;
// Generate a random sortable ID
let id = Id::generate();
println!("ID: {}", id);
// Generate multiple IDs
let ids = Id::generate_multiple(5);
assert_eq!(ids.len(), 5);
// Parsing IDs
let id_str = "01ARZ3NDEKTSV4RRFFQ69G5FAV";
let id: Id = id_str.parse().unwrap();
// For distributed systems where each worker needs to generate unique IDs:
let mut g = WorkerIdGenerator::new(1);
let id = g.generate();
assert_ne!(g.generate(), id);
// Generating multiple IDs at once is more efficient:
let mut g = WorkerIdGenerator::new(1);
let ids = g.generate_multiple(3);
assert_eq!(ids.len(), 3);
use bomboni_common::date_time::UtcDateTime;
// Get the current time
let now = UtcDateTime::now();
// Create from Unix timestamp
let dt = UtcDateTime::from_seconds(1609459200).unwrap();
assert_eq!(dt.to_string(), "2021-01-01T00:00:00Z");
// Convert from string
let dt = "1970-01-01T00:00:01Z".parse::<UtcDateTime>().unwrap();
assert_eq!(dt.timestamp(), (1, 0));
serde: Enable serialization with serdetokio: Enable async APIs using tokiochrono: Enable conversion with the chrono cratewasm: Enable WebAssembly supportpostgres: Enable PostgreSQL type conversionsmysql: Enable MySQL type conversions