https://github.com/dylanhart/ulid-rs
This is a Rust implementation of the ulid project
https://github.com/dylanhart/ulid-rs
identifier rust sortable ulid uuid
Last synced: 28 days ago
JSON representation
This is a Rust implementation of the ulid project
- Host: GitHub
- URL: https://github.com/dylanhart/ulid-rs
- Owner: dylanhart
- License: mit
- Created: 2017-06-08T14:15:56.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2025-03-17T02:13:18.000Z (11 months ago)
- Last Synced: 2025-05-19T00:51:18.860Z (8 months ago)
- Topics: identifier, rust, sortable, ulid, uuid
- Language: Rust
- Homepage: https://crates.io/crates/ulid
- Size: 105 KB
- Stars: 422
- Watchers: 4
- Forks: 40
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ulid-rs

[](https://crates.io/crates/ulid)
[](https://docs.rs/ulid)
This is a Rust implementation of the [ulid][ulid] project which provides
Universally Unique Lexicographically Sortable Identifiers.
[ulid]: https://github.com/ulid/spec
## Quickstart
```rust
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][serde_mod] and [serde docs][serde_docs] for more information.
* **`uuid`**: Implements infallible conversions between ULIDs and UUIDs from the [`uuid`][uuid] crate via the [`std::convert::From`][trait_from] trait.
[serde_mod]: https://docs.rs/ulid/latest/ulid/serde/index.html
[serde_docs]: https://serde.rs/field-attrs.html#with
[uuid]: https://github.com/uuid-rs/uuid
[trait_from]: https://doc.rust-lang.org/std/convert/trait.From.html
## Benchmark
Benchmarks were run on my desktop (Win 10/WSL2 Ubuntu; Ryzen 7 5950x). Run them yourself with `cargo bench`.
```text
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)
```