Random Slug Generator
What it says on the tin - this generates random text slugs in Rust.
Usable as a standalone binary, web applications as a WebAssembly module (WASM), or even as a Python module.
Why?
I needed a way to generate random slugs for a web project so thought it was a good opporunity to try out Rust's WebAssembly capabilities while also being able to use the same code as a zero-dependency python module for other projects.
Key features
- Generates unique random slugs for a input length in words
- Blazingly fast
- Zero dependencies
- Customisable slug length in words
- Over half a million unique combinations for 2-word slugs ranging up to over 280 trillion unique combinations for 5-word slugs.
Usage
As a Rust binary
cargo run --release [length in words] [number of slugs]
As a standalone binary
cargo build --release
[build path]/rustyrs [length in words] [number of slugs]
Example Output
proctor-slimmer-guillemot
unsafe-warlike-avocado
garbled-pulled-stork
answerable-quick-whale
floral-apportioned-bobcat
As a WASM module
cargo install wasm-pack
wasm-pack build --target web --features wasm
Then from JS/TS:
import init, { random_slugs } from './pkg/rustyrs.js';
init();
const slugs: string[] = random_slugs(3, 5);
console.log(slugs);
See index.html for a full example
As a Python module
Install from PyPI
pip install rustyrs
Build from source
python -m venv venv
source venv/bin/activate
pip install maturin
maturin develop --features python
Then from Python:
from rustyrs import random_slugs
slugs: list[str] = random_slugs(3, 5)
Other features:
Performance
- 0.5 million x 2 word slugs: ~0.47s
- 1 million x 5 word slugs: ~1.717s
License
MIT