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

haikunator

为您的 Rust 应用程序生成类似 Heroku 的随机名称

3 个版本

使用旧的 Rust 2015

0.1.2 2015年12月24日
0.1.1 2015年12月24日
0.1.0 2015年12月24日

#1595开发工具

Download history 131/week @ 2024-04-05 150/week @ 2024-04-12 225/week @ 2024-04-19 169/week @ 2024-04-26 57/week @ 2024-05-03 303/week @ 2024-05-10 46/week @ 2024-05-17 119/week @ 2024-05-24 191/week @ 2024-05-31 189/week @ 2024-06-07 153/week @ 2024-06-14 151/week @ 2024-06-21 161/week @ 2024-06-28 93/week @ 2024-07-05 67/week @ 2024-07-12 101/week @ 2024-07-19

426 每月下载量
用于 userman-auth

MIT 许可证

11KB
86

rust-haikunator

Build Status Coverage Status

为您的 Rust 应用程序生成类似 Heroku 的随机名称。

安装

将依赖项添加到您的 Config.toml

[dependencies]

haikunator = "0.1.0"

使用

包含 crate;创建一个 Haikunator 实例;然后调用 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"
}

更多示例请参阅测试文件 tests/lib.rs

选项

以下选项可用

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,
}

注意:如果 token_hex 为 true,则忽略 token_chars 的值。

贡献

鼓励每个人帮助改进此项目。以下是一些您可以提供帮助的方式

其他语言

Haikunator 也适用于其他语言。查看它们

许可证

rust-haikunator 在 MIT 许可证 下可用。

依赖项

~320–540KB