#uuid #guid

shortguid

Short URL-safe Base64 encoded UUIDs

7 releases (breaking)

0.7.0 May 17, 2024
0.6.0 Aug 20, 2023
0.5.0 Jun 24, 2023
0.4.0 Jun 24, 2023
0.1.0 Apr 7, 2023

#1297 in Data structures

Download history 142/week @ 2025-07-26 86/week @ 2025-08-02 136/week @ 2025-08-09 234/week @ 2025-08-16 146/week @ 2025-08-23 127/week @ 2025-08-30 100/week @ 2025-09-06 114/week @ 2025-09-13 91/week @ 2025-09-20 134/week @ 2025-09-27 153/week @ 2025-10-04 207/week @ 2025-10-11 269/week @ 2025-10-18 177/week @ 2025-10-25 125/week @ 2025-11-01 153/week @ 2025-11-08

742 downloads per month
Used in yeet-yoink

EUPL-1.2

30KB
466 lines

ShortGuid

codecov

Short URL-safe Base64 encoded UUIDs.


ShortGuids transparently represent UUID types but use only 22 characters in their string representation, as opposed to 36 characters for a dashed UUID or 32 without dashes.

#[test]
fn it_works() {
    let uuid = Uuid::try_parse("c9a646d3-9c61-4cb7-bfcd-ee2522c8f633").unwrap();
    let from_uuid = ShortGuid::from(uuid);
    let parsed_uuid = ShortGuid::try_parse("c9a646d3-9c61-4cb7-bfcd-ee2522c8f633").unwrap();
    let parsed_short = ShortGuid::try_parse("yaZG05xhTLe_ze4lIsj2Mw").unwrap();

    assert_eq!(from_uuid, uuid);
    assert_eq!(from_uuid, "yaZG05xhTLe_ze4lIsj2Mw");
    assert_eq!(from_uuid, "c9a646d3-9c61-4cb7-bfcd-ee2522c8f633");
    assert_eq!(from_uuid, parsed_uuid);
    assert_eq!(from_uuid, parsed_short);

    let random = ShortGuid::new_random();
    assert_ne!(from_uuid, random);
}

Fuzzing

This uses cargo-fuzz. See fuzz/fuzzers for the available fuzzing scripts. To run, use an invocation like these:

cargo +nightly fuzz run roundtrip
cargo +nightly fuzz run decode_random
cargo +nightly fuzz run encode_random
cargo +nightly fuzz run equals

Dependencies

~0.4–1.4MB
~26K SLoC