bomboni_common crate provides common utilities used throughout the Bomboni library, including sortable unique identifiers and UTC date-time handling.
Id
A semi-globally unique and sortable identifier based on ULID (Universally Unique Lexicographically Sortable Identifier).Type Definition
Id type provides both uniqueness and sortability, making it ideal for distributed systems and database records.
Methods
Creates a new ID from a 128-bit integer.
Generates a new random sortable ID.
Generates multiple random sortable IDs. Generated IDs are monotonically increasing.Panics: Panics if the ULID generator fails to generate an ID.
Creates an ID from worker parts. Useful for distributed ID generation.Panics: Panics if the timestamp, worker ID, or sequence number is too large.
Creates an ID from time and a random number.
Decodes the ID into worker parts: timestamp, worker ID, and sequence number.
Decodes the ID into time and randomness parts.
Traits
TheId type implements several standard traits:
Display- Formats the ID as a ULID stringFromStr- Parses an ID from a ULID stringFrom<u8>,From<u16>,From<u32>,From<u64>- Converts from unsigned integersFrom<i8>,From<i16>,From<i32>,From<i64>,From<i128>- Converts from signed integersFrom<Ulid>andInto<Ulid>- Converts to/from ULIDInto<u128>- Converts to 128-bit integerSerializeandDeserialize(withserdefeature)
ParseIdError
Errors that can occur when parsing anId from a string.
WorkerIdGenerator
Generator for IDs with a specific worker ID, suitable for distributed systems.Type Definition
Methods
Creates a new worker ID generator with the specified worker ID.
Generates a new ID with the worker’s identifier. Each call increments an internal sequence number.
Generates a new ID asynchronously. Same as
generate but async-friendly.Requires: tokio featureGenerates multiple IDs at once. More efficient than calling
generate repeatedly.Generates multiple IDs asynchronously. Same as
generate_multiple but async-friendly.Requires: tokio featureUtcDateTime
A date and time in the UTC time zone with support for various serialization formats.Type Definition
Constants
The Unix epoch (1970-01-01 00:00:00 UTC).
Methods
Returns the current UTC date and time.
Creates a new UTC date time from seconds and nanoseconds since Unix epoch.If the timestamp is invalid, returns Unix epoch.
Creates a UTC date time from seconds and nanoseconds.Returns
UtcDateTimeError::NotUtc if the timestamp is not valid.Creates a UTC date time from seconds since the Unix epoch.
Creates a UTC date time from nanoseconds since the Unix epoch.
Returns the timestamp as (seconds, nanoseconds) tuple.
Parses an RFC 3339 formatted date time string.
Formats the date time as an RFC 3339 string.
Traits
TheUtcDateTime type implements several traits:
Display- Formats as RFC 3339 stringFromStr- Parses from RFC 3339 stringFrom<OffsetDateTime>andInto<OffsetDateTime>From<PrimitiveDateTime>andInto<PrimitiveDateTime>From<SystemTime>TryFrom<DateTime<Utc>>andInto<DateTime<Utc>>(withchronofeature)SerializeandDeserialize(withserdefeature)
UtcDateTimeError
Errors that can occur when working withUtcDateTime.
Feature Flags
Thebomboni_common crate supports the following optional features:
Enables serialization and deserialization support via serde.
Enables async methods for ID generation using tokio runtime.
Enables conversions between
UtcDateTime and chrono’s DateTime<Utc>.Enables WebAssembly support with JavaScript interop.
Enables PostgreSQL type conversions for
Id and UtcDateTime.Enables MySQL type conversions for
Id and UtcDateTime.