#uuid

shortguid

Short URL-safe Base64 encoded UUIDs

6 releases (breaking)

0.6.0 Aug 20, 2023
0.5.0 Jun 24, 2023
0.4.0 Jun 24, 2023
0.3.0 Apr 8, 2023
0.1.0 Apr 7, 2023

#23 in #uuid

Download history 62/week @ 2023-06-20 40/week @ 2023-06-27 47/week @ 2023-07-04 2/week @ 2023-07-11 9/week @ 2023-07-25 10/week @ 2023-08-01 19/week @ 2023-08-08 43/week @ 2023-08-15 25/week @ 2023-08-22 7/week @ 2023-08-29 21/week @ 2023-09-05 27/week @ 2023-09-12 10/week @ 2023-09-19

74 downloads per month

EUPL-1.2

26KB
437 lines

ShortGuid

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

~385–630KB
~12K SLoC