#heroku #haiku #random-name #unique-name #short-name

haikunator

Generate Heroku-like random names to use in your Rust applications

3 releases

Uses old Rust 2015

0.1.2 Dec 24, 2015
0.1.1 Dec 24, 2015
0.1.0 Dec 24, 2015

#5 in #heroku

Download history 117/week @ 2024-04-08 198/week @ 2024-04-15 238/week @ 2024-04-22 101/week @ 2024-04-29 79/week @ 2024-05-06 290/week @ 2024-05-13 65/week @ 2024-05-20 127/week @ 2024-05-27 205/week @ 2024-06-03 149/week @ 2024-06-10 209/week @ 2024-06-17 164/week @ 2024-06-24 85/week @ 2024-07-01 106/week @ 2024-07-08 75/week @ 2024-07-15 119/week @ 2024-07-22

411 downloads per month
Used in userman-auth

MIT license

11KB
86 lines

rust-haikunator

Build Status Coverage Status

Generate Heroku-like random names to use in your Rust applications.

Installation

Add to your Config.toml dependencies

[dependencies]

haikunator = "0.1.0"

Usage

Include the crate; create a Haikunator instance; then call haikunate.

extern crate haikunator;

use haikunator::{Haikunator};

fn main() {
    // normal usage
    let haikunator = Haikunator::default();    
    println!("{}", haikunator.haikunate()); // => fancy-cloud-7181

    // custom length (default=4)
    let mut haikunator = Haikunator::default();
    haikunator.token_length = 9;
    println!("{}", haikunator.haikunate()); // => rapid-mode-572457286

    // use hex instead of numbers
    let mut haikunator = Haikunator::default();
    haikunator.token_hex = true;
    println!("{}", haikunator.haikunate()); // => "misty-boat-bd01"

    // use custom chars instead of numbers/hex
    // unicode works too
    let mut haikunator = Haikunator::default();
    haikunator.token_chars = "HAIKUNATE忠犬ハチ公";
    println!("{}", haikunator.haikunate()); // => "divine-tiger-NKKチ"

    // don't include a token
    let mut haikunator = Haikunator::default();
    haikunator.token_length = 0;
    println!("{}", haikunator.haikunate()); // => "lingering-term"

    // use a different delimiter
    let mut haikunator = Haikunator::default();
    haikunator.delimiter = ":";
    println!("{}", haikunator.haikunate()); // => "young:cell:5426"

    // no token, space delimiter
    let mut haikunator = Haikunator::default();
    haikunator.token_length = 0;
    haikunator.delimiter = " ";
    println!("{}", haikunator.haikunate()); // => "wandering coke"

    // no token, empty delimiter
    let mut haikunator = Haikunator::default();
    haikunator.token_length = 0;
    haikunator.delimiter = "";
    println!("{}", haikunator.haikunate()); // => "freetooth"

    // custom nouns and/or adjectives
    let haikunator = Haikunator {
        adjectives: &["dandy", "froody", "happy"],
        nouns: &["whale", "towel", "earth"],
        delimiter: "-",
        token_length: 3,
        token_hex: false,
        token_chars: "24",
    };
    println!("{}", haikunator.haikunate()); // => "happy-earth-444"
}

See the test files at tests/lib.rs for more examples.

Options

The following options are available:

pub struct Haikunator<'a> {
    pub adjectives: &'a [&'a str],
    pub nouns: &'a [&'a str],
    pub delimiter: &'a str,
    pub token_length: usize,
    pub token_hex: bool,
    pub token_chars: &'a str,
}

Note: If token_hex is true, the value of token_chars is ignored.

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

Other Languages

Haikunator is also available in other languages. Check them out:

License

rust-haikunator is available under the MIT License.

Dependencies

~330–560KB