alphaid 0.2.0

Generate Youtube-Like IDs with Rust
Documentation
  • Coverage
  • 61.11%
    11 out of 18 items documented3 out of 13 items with examples
  • Size
  • Source code size: 18.97 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.96 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • importcjj/alphaid
    12 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • importcjj

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