bomboni_common
Common utilities for the Bomboni library.
This crate provides essential utilities for building distributed systems and applications.
Features
- Unique Identifiers: ULID-based sortable and unique ID generation supporting both random and worker-based approaches
- UTC DateTime Handling: A UTC-focused datetime type
- WASM Compatible: Full support for WebAssembly targets
- Database Support: PostgreSQL and MySQL integration via optional features
Examples
Unique IDs
use ;
use FromStr;
// Generate a random sortable ID
let id = generate;
println!;
// Generate multiple IDs
let ids = generate_multiple;
assert_eq!;
// 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 = new;
let id = g.generate;
assert_ne!;
// Generating multiple IDs at once is more efficient:
let mut g = new;
let ids = g.generate_multiple;
assert_eq!;
UTC DateTime
use UtcDateTime;
// Get the current time
let now = now;
// Create from Unix timestamp
let dt = from_seconds.unwrap;
assert_eq!;
// Convert from string
let dt = "1970-01-01T00:00:01Z"..unwrap;
assert_eq!;
Cargo Features
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