short-uuid
Generate and translate standard UUIDs into shorter or just different formats and back.
A port of the JavaScript npm package short-uuid so big thanks to the author.
An example of short uuid string in default flickrBase58 alphabet:
mhvXdrZT4jP5T8vBxuvm75
Getting started
Install the package with cargo:
or add it to your Cargo.toml:
[]
= "0.2.0"
Examples
Generate short uuidv4 encoded in flickrBase58 format:
use ShortUuid;
let shortened_uuid = generate;
Generate short uuidv4 encoded in flickrBase58 format using macro:
use short;
let shortened_uuid = short!;
Generate short uuidv4 using custom alphabet:
use ;
let custom_alphabet = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
let translator = new.unwrap;
let custom_short = generate;
let custom_short_string = custom_short.to_string;
Get shortened uuid from standard uuid:
use ShortUuid;
// create normal uuid v4
let uuid = new_v4;
let short = from_uuid;
Get shortened uuid from standard uuid using custom alphabet:
use ;
let custom_alphabet = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
let translator = new.unwrap;
let uuid = new_v4;
let short_custom = from_uuid;
let short_custom_string = short_custom.to_string;
Get shortened uuid from uuid string:
use ShortUuid;
let uuid_str = "3cfb46e7-c391-42ef-90b8-0c1d9508e752";
let short_uuid = from_uuid_str;
Get shortened uuid from uuid string using custom alphabet:
use ;
let custom_alphabet = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
let translator = new.unwrap;
let uuid_str = "3cfb46e7-c391-42ef-90b8-0c1d9508e752";
let short_custom = from_uuid_str.unwrap;
let short_custom_string = short_custom.to_string;
Serialize and deserialize struct with short uuid (you must enable the serde feature):
[]
= { = "0.2.0", = ["serde"] }
Example usage: