Skip to main content

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.

Key features

  • No dependencies
  • Fast
  • Customizable 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

# 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 random_slugs
slugs: list[str] = random_slugs(3, 5)

# slugs: ['reflecting-unsealed-mamba', 'disabling-addicting-asp', 'pliable-begotten-barnacle', 'vaulting-telepathic-caracal', 'canonical-graven-beetle']

Other features:

  • get_slug(word_length: int) -> str: Generate a single slug of a specific length
  • SlugGenerator(word_length: int): Create a generator object to generate slugs of a specific length. Can generate slugs infinitely.
    from rustyrs import SlugGenerator
    gen = SlugGenerator(3)
    print(next(gen)) # 'unwieldy-unsuspecting-ant'
    
  • combinations(word_length: int) -> int: Get the number of possible combinations for a given word length
    from rustyrs import combinations
    print(combinations(3)) # 556,284
    

Performance

  • 1m x 2 word slugs: ~4.995s
  • 1m x 5 word slugs: ~10.447s

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 Distributions

rustyrs-0.4.1-py3-none-win_amd64.whl (64.7 kB view hashes)

Uploaded Python 3 Windows x86-64

rustyrs-0.4.1-py3-none-win32.whl (65.1 kB view hashes)

Uploaded Python 3 Windows x86

rustyrs-0.4.1-py3-none-musllinux_1_2_x86_64.whl (177.5 kB view hashes)

Uploaded Python 3 musllinux: musl 1.2+ x86-64

rustyrs-0.4.1-py3-none-musllinux_1_2_i686.whl (191.6 kB view hashes)

Uploaded Python 3 musllinux: musl 1.2+ i686

rustyrs-0.4.1-py3-none-musllinux_1_2_armv7l.whl (270.0 kB view hashes)

Uploaded Python 3 musllinux: musl 1.2+ ARMv7l

rustyrs-0.4.1-py3-none-musllinux_1_2_aarch64.whl (846.5 kB view hashes)

Uploaded Python 3 musllinux: musl 1.2+ ARM64

rustyrs-0.4.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (5.7 kB view hashes)

Uploaded Python 3 manylinux: glibc 2.17+ s390x

rustyrs-0.4.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (6.1 kB view hashes)

Uploaded Python 3 manylinux: glibc 2.17+ ppc64le

rustyrs-0.4.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (6.0 kB view hashes)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

rustyrs-0.4.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (183.3 kB view hashes)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

rustyrs-0.4.1-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (5.5 kB view hashes)

Uploaded Python 3 manylinux: glibc 2.5+ x86-64

rustyrs-0.4.1-py3-none-manylinux_2_5_i686.manylinux1_i686.whl (5.6 kB view hashes)

Uploaded Python 3 manylinux: glibc 2.5+ i686

rustyrs-0.4.1-py3-none-macosx_11_0_arm64.whl (4.0 kB view hashes)

Uploaded Python 3 macOS 11.0+ ARM64

rustyrs-0.4.1-py3-none-macosx_10_12_x86_64.whl (3.8 kB view hashes)

Uploaded Python 3 macOS 10.12+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page