Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/importcjj/alphaid
Generate Youtube-Like IDs with Rust
https://github.com/importcjj/alphaid
alphaid basex encoder-decoder hashid hex rust youtube
Last synced: 2 months ago
JSON representation
Generate Youtube-Like IDs with Rust
- Host: GitHub
- URL: https://github.com/importcjj/alphaid
- Owner: importcjj
- Created: 2019-12-15T16:14:14.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-22T11:15:53.000Z (over 4 years ago)
- Last Synced: 2024-10-13T08:40:51.845Z (3 months ago)
- Topics: alphaid, basex, encoder-decoder, hashid, hex, rust, youtube
- Language: Rust
- Size: 15.6 KB
- Stars: 12
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ALPHAID
Generate Youtube-Like IDs with Rust
[![Build Status](https://travis-ci.com/importcjj/alphaid.svg?token=ZZrg3rRkUA8NUGrjEsU9&branch=master)](https://travis-ci.com/importcjj/alphaid) [![crates.io](https://img.shields.io/badge/crates.io-latest-%23dea584)](https://crates.io/crates/alphaid)
## Basic Usage
```rust
use alphaid::AlphaId;let alphaid = AlphaId::::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.```rust
use alphaid::AlphaId;let alphaid = AlphaId::::new();
assert_eq!(alphaid.encode(0), Ok(b"a".to_vec()));
assert_eq!(alphaid.decode(b"a"), Ok(0));let alphaid = AlphaId::::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-_````rust
use alphaid::AlphaId;
let alphaid = AlphaId::::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](https://kvz.io/create-short-ids-with-php-like-youtube-or-tinyurl.html)