1 unstable release

0.1.0 Dec 28, 2018

#19 in #ulid

MIT license

30KB
656 lines

yulid

A Rust implementation of the ULID spec that aims to be as similar to uuid as possible.

Supports

  • Generation with rand API (by default)
  • Serialisation and deserialisation with serde (with feature)
  • Converting to and from UUIDs provided by the uuid crate (with feature)

Examples

use yulid::Ulid;

fn main() {
  // create a new ULID
  let ulid = Ulid::new();

  // print the lowercase form
  println!("{}", ulid.to_lowercase());

  // get the DateTime<Utc> this ULID contains
  let timestamp = ulid.timestamp();
}
use rand::{Rng, thread_rng};
use yulid::Ulid;

fn main() {
  // generate a ULID using rand
  let ulid: Ulid = thread_rng().gen();
}

lib.rs:

Generate and parse ULIDs.

Provides support for universally unique lexicographically sortable identifiers (ULIDs). A ULID is a combination of a 48-bit timestamp and an 80-bit unique number, stored as 16 octets. ULIDs are used to assign identifiers to entities without requiring a central allocating authority.

They are particularly useful in distributed systems, though can be used in disparate areas, such as databases and network protocols. Typically a UUID is displayed in a readable string form as a sequence of 26 base32 digits.

The uniqueness property is not strictly guaranteed, however for all practical purposes, it can be assumed that an unintentional collision would be extremely unlikely.

Dependencies

~1.6–2.3MB
~35K SLoC