No project description provided
Project description
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.
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
# If wasm pack is not already installed
cargo install wasm-pack
# build the WASM module
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);
// slugs: ['postpartum-regal-taipan', 'devastating-elven-salamander', 'immense-ambivalent-wren', 'philosophical-bandaged-gaur', 'outlaw-noncommercial-sunfish']
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 generate_slugs
slugs: list[str] = generate_slugs(3, 5)
# slugs: ['reflecting-unsealed-mamba', 'disabling-addicting-asp', 'pliable-begotten-barnacle', 'vaulting-telepathic-caracal', 'canonical-graven-beetle']
Performance
- 1m x 2 word slugs: ~4.995s
- 1m x 5 word slugs: ~10.447s
Word Data
Sourced from Corpora by Darius Kazemi
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for rustyrs-0.3.3-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f955aad80b63344faf46b4f857d39ab888c934027abc25b9ab52b6402ba20fcb |
|
MD5 | 884ebcbadaf7a12380c27cc222a9abe1 |
|
BLAKE2b-256 | 1f0eb04a9a4c4e32434f15c423989a55ba55fe750d24e556cbc833650f6d152d |