Crates.io | alphaid |
lib.rs | alphaid |
version | 0.2.0 |
source | src |
created_at | 2019-12-26 03:57:07.697622 |
updated_at | 2020-05-22 11:17:10.806292 |
description | Generate Youtube-Like IDs with Rust |
homepage | |
repository | https://github.com/importcjj/alphaid |
max_upload_size | |
id | 192403 |
size | 19,499 |
Generate Youtube-Like IDs with Rust
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));
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));
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));