ngortheone / ulid-rs

This is a Rust implementation of the ulid project

Home Page:https://crates.io/crates/ulid

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

// 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());

Optional features

  • 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 laptop. Run them yourself with cargo bench.

test bench_from_string        ... bench:          34 ns/iter (+/- 0)
test bench_from_time          ... bench:          16 ns/iter (+/- 0)
test bench_generator_generate ... bench:          56 ns/iter (+/- 0)
test bench_new                ... bench:          69 ns/iter (+/- 1)
test bench_to_str             ... bench:          14 ns/iter (+/- 0)
test bench_to_string          ... bench:         116 ns/iter (+/- 1)

About

This is a Rust implementation of the ulid project

https://crates.io/crates/ulid

License:MIT License


Languages

Language:Rust 100.0%