[][src]Crate alphaid

Generate Youtube-Like IDs with Rust.

Basic Usage

use alphaid::AlphaId;

let alphaid = AlphaId::new();
assert_eq!(alphaid.encode(1350997667), b"90F7qb");
assert_eq!(alphaid.decode(b"90F7qb"), Ok(1350997667));

Padding

Specifies the minimum length of the encoded result.

use alphaid::AlphaId;

let alphaid = AlphaId::new();
assert_eq!(alphaid.encode(0), b"a");
assert_eq!(alphaid.decode(b"a"), Ok(0));

Charaters set

Sets the characters set. Default to abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-_

use alphaid::AlphaId;
let alphaid = AlphaId::builder().pad(2)
    .chars("ABCDEFGHIJKLMNOPQRSTUVWXYZ".as_bytes().to_vec())
    .build();
assert_eq!(alphaid.encode(0), b"AB");
assert_eq!(alphaid.decode(b"AB"), Ok(0));

Reference

Create Youtube-Like IDs

Structs

AlphaId

Used for encoding and decoding.

Builder

A builder for a AlphaId.

Enums

DecodeError