3 个版本
使用旧的 Rust 2015
0.1.2 | 2015年12月24日 |
---|---|
0.1.1 | 2015年12月24日 |
0.1.0 | 2015年12月24日 |
#1595 在 开发工具
426 每月下载量
用于 userman-auth
11KB
86 行
rust-haikunator
为您的 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 也适用于其他语言。查看它们
- Node: https://github.com/Atrox/haikunatorjs
- .NET: https://github.com/Atrox/haikunator.net
- Python: https://github.com/Atrox/haikunatorpy
- PHP: https://github.com/Atrox/haikunatorphp
- Java: https://github.com/Atrox/haikunatorjava
- Dart: https://github.com/Atrox/haikunatordart
- Ruby: https://github.com/usmanbashir/haikunator
许可证
rust-haikunator 在 MIT 许可证 下可用。
依赖项
~320–540KB