Crate upid

Source
Expand description

§upid

Rust implementation of UPID, an alternative to UUID and ULID that includes a useful four-character prefix.

It is still stored as a u128 binary, is still sortable by date, and has 64 bits of randomness. It uses a modified form of Crockford’s base32 alphabet that uses lower-case and prioritises letters so that any four-letter alpha prefix can be specified.

§Quickstart

use upid::Upid;
let upid = Upid::new("user");

let text = upid.to_string();

let same = Upid::from_string(&text);
assert_eq!(upid, same.unwrap());

If an invalid prefix is specified, it will be handled as follows:

  • invalid letters (not in the ENCODE alphabet) replaced by ‘z’
  • too short will be right-padded with ‘z’
  • too long will be clipped to four characters
use upid::Upid;
let upid = Upid::new("00");
assert_eq!(upid.prefix(), "zzzz");

Structs§

Upid
A Upid is a unique 128-bit identifier is sortable and has a useful prefix.

Enums§

DecodeError
An error that can occur when decoding a base32 string

Constants§

ENCODE
32-character alphabet modified from Crockford’s Numbers first for sensible sorting, but full lower-case latin alphabet so any sensible prefix can be used Effectively a mapping from 8 bit byte -> 5 bit int -> base32 character