souvenir

Crates.iosouvenir
lib.rssouvenir
version0.5.5
created_at2024-10-05 23:50:37.746491+00
updated_at2025-09-06 21:28:45.584785+00
descriptionPrefixed identifier library
homepage
repositoryhttps://github.com/bjzsh/souvenir
max_upload_size
id1398565
size54,314
Brian Shao (bjzsh)

documentation

README

souvenir

A type-safe, tagged identifier library.

The crate primarily provides the Id struct, which stores a 128-bit identifier with its corresponding type (tag). The String representation of an Id is the type's tag and the 128-bit value encoded into a variant of Crockford Base 32.

Here is a simple example of how this crate can be used.

use souvenir::Id;

let id: Id = Id::random("user".parse().unwrap());
println!("{}", id);

let id2: Id = Id::parse("user_02v58c5a3fy30k560qrtg4").unwrap();
assert_eq!(id2.to_string(), "user_02v58c5a3fy30k560qrtg4");

Integrations for various libraries and databases are also (optionally) available:

  • (De)serialization with serde
  • Random ID generation with rand
  • Postgres, MySQL, and Sqlite support with sqlx and diesel
Commit count: 54

cargo fmt