Crate allwords[][src]

Expand description

allwords is a crate that allows you to generate words over a given alphabet.

Word generation can be useful in several scenarios:

  • Pseudo-random data generation (e.g. testing / mocking)
  • Brute forcing of keys / passwords
  • Id or Serial number generation

The basic idea for using this library is that you create an Alphabet with a set of characters and then you can use it to generate a WordsIterator. You can use the iterator to generate all the possible words over the alphabet.

For instance if you want to generate all the possible words containing "a", "b", "c" with a maximum length of 3 chars:

use allwords::{Alphabet};

let a = Alphabet::from_chars_in_str("abc").unwrap();

let words: Vec<String> = a.all_words(Some(3)).collect();

let expected_words: Vec<String> = [
    "a", "b", "c",
    "aa", "ab", "ac", "ba", "bb", "bc", "ca", "cb", "cc",
    "aaa", "aab", "aac", "aba", "abb", "abc", "aca", "acb", "acc",
    "baa", "bab", "bac", "bba", "bbb", "bbc", "bca", "bcb", "bcc",
    "caa", "cab", "cac", "cba", "cbb", "cbc", "cca", "ccb", "ccc"]
    .iter()
    .map(|s| s.to_string())
    .collect();

assert_eq!(words, expected_words);

Structs

A representation of an alphabet

A iterator that can generate words for a given alphabet