2 unstable releases

0.2.0 May 22, 2020
0.1.0 Dec 26, 2019

#4 in #hash-id

Download history 2/week @ 2025-08-17 3/week @ 2025-08-24 3/week @ 2025-08-31 3/week @ 2025-09-14 15/week @ 2025-09-21 4/week @ 2025-09-28 8/week @ 2025-10-05 34/week @ 2025-10-12 15/week @ 2025-10-19 10/week @ 2025-10-26 12/week @ 2025-11-02

73 downloads per month
Used in zero4rs

MIT/Apache

11KB
159 lines

ALPHAID

Generate Youtube-Like IDs with Rust

Build Status crates.io

Basic Usage

use alphaid::AlphaId;

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

Padding

Specifies the minimum length of the encoded result.

use alphaid::AlphaId;

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

let alphaid = AlphaId::<u32>::builder().pad(5).build();
assert_eq!(alphaid.encode(0), Ok(b"aaaab".to_vec()));
assert_eq!(alphaid.decode(b"aaaab"), Ok(0));

Charaters set

Sets the characters set. Default to abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-_

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

Reference

Create Youtube-Like IDs

Dependencies

~465KB