ulid (1.2.0)

Published 2024-07-25 19:49:55 -07:00 by jtai

Installation

[registry]
default = "forgejo"

[registries.forgejo]
index = "sparse+" # Sparse index
# index = "" # Git

[net]
git-fetch-with-cli = true
cargo add ulid@1.2.0

About this package

a Universally Unique Lexicographically Sortable Identifier implementation

ulid-rs

Build Status Crates.io docs.rs

This is a Rust implementation of the ulid project which provides Universally Unique Lexicographically Sortable Identifiers.

Quickstart

use ulid::Ulid;

// Generate a ulid
let ulid = Ulid::new();

// Generate a string for a ulid
let s = ulid.to_string();

// Create from a String
let res = Ulid::from_string(&s);

assert_eq!(ulid, res.unwrap());

Crate Features

  • std (default): Flag to toggle use of std and rand. Disable this flag for #[no_std] support.
  • serde: Enables serialization and deserialization of Ulid types via serde. ULIDs are serialized using their canonical 26-character representation as defined in the ULID standard. An optional ulid_as_u128 module is provided, which enables serialization through an Ulid's inner u128 primitive type. See the documentation and serde docs for more information.
  • uuid: Implements infallible conversions between ULIDs and UUIDs from the uuid crate via the std::convert::From trait.

Benchmark

Benchmarks were run on my desktop (Win 10/WSL2 Ubuntu; Ryzen 7 5950x). Run them yourself with cargo bench.

test bench_from_string        ... bench:          13 ns/iter (+/- 0)
test bench_from_time          ... bench:          13 ns/iter (+/- 0)
test bench_generator_generate ... bench:          29 ns/iter (+/- 0)
test bench_new                ... bench:          31 ns/iter (+/- 1)
test bench_to_str             ... bench:           7 ns/iter (+/- 0)
test bench_to_string          ... bench:          19 ns/iter (+/- 0)

Dependencies

ID Version
bytes ^1.4.0
postgres-types ^0.2.6
rand ^0.8
serde ^1.0
uuid ^1.1
bencher ^0.1
serde_derive ^1.0
getrandom ^0.2
web-time ^1
wasm-bindgen-test ^0.3

Keywords

ulid uuid sortable identifier
Details
Cargo
2024-07-25 19:49:55 -07:00
14
dylanhart <dylan96hart@gmail.com>
MIT
11 KiB
Assets (1)
Versions (1) View all
1.2.0 2024-07-25