tbicr / shorter-uuid-rs

Simple UUID shortener for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

shorter_uuid

Latest version Documentation

This create is a simple UUID shortener inspired by keiko/uuid-shortener, pascaldevink/shortuuid and skorokithakis/shortuuid.

Usage

Add this to your Cargo.toml:

[dependencies]
shorter_uuid = { version = "0.1", default_features = false }

Note: Disabling of default features disables proptest arbitrary module.

Then use it in your project like that:

use uuid::Uuid;
use shorter_uuid::{Expand, Shorten};

fn main() -> Result<(), Error> {
    // Expands string with `BASE57` alphabet.
    let e = Uuid::expand("mavTAjNm4NVztDwh4gdSrQ")?;
    let u = Uuid::parse_str("806d0969-95b3-433b-976f-774611fdacbb")?;
    
    // Encodes `u` with `BASE57` alphabet.
    assert_eq!(format!("{}", u.shorten()), "mavTAjNm4NVztDwh4gdSrQ"); 
    assert_eq!(e, u);
    Ok(())
}

Check API documentation for details.

About

Simple UUID shortener for Rust

License:Other


Languages

Language:Rust 100.0%