Generate and translate standard uuids into shorter formats and back.

Overview

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:

cargo add short-uuid

or add it to your Cargo.toml:

[dependencies]
short-uuid = "0.1.0"

Examples

Generate short uuidv4 encoded in flickrBase58 format:

use short_uuid::ShortUuid;

let shortened_uuid = ShortUuid::generate();

Generate short uuidv4 encoded in flickrBase58 format using macro:

use short_uuid::short;

let shortened_uuid = short!();

Generate short uuidv4 using custom alphabet:

use short_uuid::{ShortUuidCustom, CustomTranslator};

let custom_alphabet = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
let translator = CustomTranslator::new(custom_alphabet).unwrap();

let custom_short = ShortUuidCustom::generate(&translator);
let custom_short_string = custom_short.to_string();

Get shortened uuid from standard uuid:

use short_uuid::ShortUuid;
// create normal uuid v4
let uuid = uuid::Uuid::new_v4();

let short = ShortUuid::from_uuid(&uuid);

Get shortened uuid from standard uuid using custom alphabet:

use short_uuid::{ShortUuidCustom, CustomTranslator};

let custom_alphabet = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
let translator = CustomTranslator::new(custom_alphabet).unwrap();

let uuid = uuid::Uuid::new_v4();
let short_custom = ShortUuidCustom::from_uuid(&uuid, &translator);
let short_custom_string = short_custom.to_string();

Get shortened uuid from uuid string:

use short_uuid::ShortUuid;

let uuid_str = "3cfb46e7-c391-42ef-90b8-0c1d9508e752";
let short_uuid = ShortUuid::from_uuid_str(&uuid_str);

Get shortened uuid from uuid string using custom alphabet:

use short_uuid::{ShortUuidCustom, CustomTranslator};

let custom_alphabet = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
let translator = CustomTranslator::new(custom_alphabet).unwrap();

let uuid_str = "3cfb46e7-c391-42ef-90b8-0c1d9508e752";
let short_custom = ShortUuidCustom::from_uuid_str(&uuid_str, &translator).unwrap();
let short_custom_string = short_custom.to_string();

References

You might also like...
Remember how cool smlinux was? It's now time to bring it back.

smbuilder Remember how cool smlinux was? It's now time to bring it back. What is smbuilder? In short, smbuilder (stylized as all lowercase) is an app

Collection of immutable and persistent data structures written in Rust, inspired by the standard libraries found in Haskell, Closure and OCaml

PRust: (P)ersistent & Immutable Data Structures in (Rust) This library houses a collection of immutable and persistent data structures, inspired by th

Interface definition generator and standard for Move packages.

Move IDL Interface definition generator and standard for Move packages. Documentation is currently extremely sparse but will be improved in the near f

epNFTs, the first partial program-owned NFT Standard powered by Instruction Introspection and Transfer Hooks!

epNFT Standard: A Comprehensive Guide Introduction to epNFTs Welcome to the epNFT-standard repository, where we explore the first program-owned NFT st

Standard Graphics is a command-line tool for printing 2D graphics from any language to any screen.
Standard Graphics is a command-line tool for printing 2D graphics from any language to any screen.

2D graphics in any programming language with just print statements!

Simple console input macros with the goal of being implemented in the standard library.

Simple console input macros with the goal of being implemented in the standard library.

A Rust program/library to write a Hello World message to the standard output.

hello-world Description hello-world is a Rust program and library that prints the line Hello, world! to the console. Why was this created? This progra

Expose standard or fully custom USB peripherals (gadgets) through a USB device controller (UDC) on Linux using Rust.

usb-gadget This library allows implementation of USB peripherals, so called USB gadgets, on Linux devices that have a USB device controller (UDC). Bot

This library provides a convenient derive macro for the standard library's std::error::Error trait.

derive(Error) This library provides a convenient derive macro for the standard library's std::error::Error trait. [dependencies] therror = "1.0" Compi

Releases(v0.1.1)
Owner
Radim Höfer
Fullstack dev 🦀
Radim Höfer
Timestamp-orderable UUIDs for Python, written in Rust.

UUIDT Timestamp-orderable UUIDs for Python, written in Rust. Installation pip install uuidt Usage import uuidt # Create a new UUIDT u = uuidt.new('my

Isaac Harris-Holt 7 Mar 12, 2023
Reddit - Liberate your Reddit Chats. This tool will export your reddit chats into a plethora of formats

Rexit Rexit - Liberate your Reddit Chats. This tool will export your Reddit chats into a plethora of formats Tool to export Reddit chats into a variet

Maximilian Pult 6 May 3, 2023
Rust low-level minimalist APNG writer and PNG reader with just a few dependencies with all possible formats coverage (including HDR).

project Wiki https://github.com/js29a/micro_png/wiki at glance use micro_png::*; fn main() { // load an image let image = read_png("tmp/test.

jacek SQ6KBQ 8 Aug 30, 2023
An open source artifact manager. Written in Rust back end and an Vue front end to create a fast and modern experience

nitro_repo Nitro Repo is an open source free artifact manager. Written with a Rust back end and a Vue front end to create a fast and modern experience

Wyatt Jacob Herkamp 30 Dec 14, 2022
Adds back-and-forth jumping between current and previous focused windows to Sway.

sway-focus-back-and-forth Implements back-and-forth movement between the current and the previous focused windows. It also can be seen as a fix to thi

Vinícius Müller 4 Aug 11, 2022
Firefox used to have this feature a while back (from Firefox 11 to 46) and it is so good, that I feel it needs revival.

3D WebPage Inspector By: Seanpm2001, Et; Al. Top README.md Read this article in a different language Sorted by: A-Z Sorting options unavailable ( af A

Sean P. Myrick V19.1.7.2 3 Nov 10, 2022
Fixed point to floating point (and back) conversion utility

fixed2float Simple utility for fixed point to real number conversions, using the VisSim (Fxm.b) and Q (Qm.n) notations. Usage as a dependency of your

Francesco Urbani 2 Aug 5, 2022
🌈 Brings back colour console to Win64 for Garry's Mod SRCDS

?? gmsv_concolormsg This module for Garry's Mod fixes x86-64 Windows 64-bit SRCDS not displaying colours. Why does it do that? Who knows! But it's eas

William 11 Oct 4, 2022
Help Skelly to find bones, combine them to build his body back

Bones Collector Help Skelly to find bones, combine them to build his body back! Game made for the bevy Jam#2. Play it here in your browser: itch.io! R

Thomas 2 Nov 15, 2022
RedMaple offers an oppinionated yet extremely flexible data modeling system based on events for back-end applications.

RedMaple offers an oppinionated yet extremely flexible data modeling system based on events for back-end applications.

Amir Alesheikh 4 Mar 5, 2023