Crates.io | mudders |
lib.rs | mudders |
version | 0.0.4 |
source | src |
created_at | 2020-03-06 11:11:13.962054 |
updated_at | 2020-03-18 09:27:35.628557 |
description | Generating Lexicographically-Evenly-Spaced Strings, or: Mudder.js in Rust. |
homepage | |
repository | https://github.com/Follpvosten/mudders |
max_upload_size | |
id | 216054 |
size | 36,024 |
Generate lexicographically-evenly-spaced strings between two strings from pre-defined alphabets.
This is a rewrite of mudderjs; thanks for the original work of the author and their contributors!
Add a dependency in your Cargo.toml:
mudders = "0.0.4"
Now you can generate lexicographically-spaced strings in a few different ways:
use mudders::SymbolTable;
// The mudder method takes a NonZeroUsize as the amount,
// so you cannot pass in an invalid value.
use std::num::NonZeroUsize;
// You can use the included alphabet table
let table = SymbolTable::alphabet();
// SymbolTable::mudder() returns a Vec containing `amount` Strings.
let result = table.mudder_one("a", "z").unwrap();
// These strings are always lexicographically placed between `start` and `end`.
let one_str = result.as_str();
assert!(one_str > "a");
assert!(one_str < "z");
// You can also define your own symbol tables
let table = SymbolTable::from_chars(&['a', 'b']).unwrap();
let result = table.mudder("a", "b", NonZeroUsize::new(2).unwrap()).unwrap();
assert_eq!(result.len(), 2);
assert!(result[0].as_str() > "a" && result[1].as_str() > "a");
assert!(result[0].as_str() < "b" && result[1].as_str() < "b");
// The strings *should* be evenly-spaced and as short as they can be.
let table = SymbolTable::alphabet();
let result = table.mudder("anhui", "azazel", NonZeroUsize::new(3).unwrap()).unwrap();
assert_eq!(result.len(), 3);
assert_eq!(vec!["aq", "as", "av"], result);
The most notable difference to Mudder.js is that currently, mudders only
supports ASCII characters (because 127 characters ought to be enough for
everyone™). Our default ::alphabet()
also only has lowercase letters.