Skip to main content

Crate wordnik_list

Crate wordnik_list 

Source
Expand description

This is a small library that exports useful methods for recognizing valid words from the Wordnik Word List. Definitions, usage, pronunciation, etymology, and examples are omitted. This library uses the official list from wordnik (last synced December 2024). Internally, it uses a static BTreeSet generated at runtime, meaning cross-thread word checking in a small footprint under 10 MB.

§Random lookup time

Averaged over 100,000 cases on a mdi-range desktop in 2024, the runtime is 200 nanoseconds in release mode and 600 nanoseconds in debug mode.

§Stability note

This crate may change internal implementation at any time to improve memory efficiency or startup time. Do not rely on the order that elements are yielded by iterators

Example:

use wordnik_list::word_exists;

let try_words = ["list", "rust", "rusty", "ruster", "abroptly", "assertion"];
// Print which words in that list are invalid
for word in try_words {
    if !word_exists(word) {
        println!("\"{}\" is not a valid word", word);
    }
}

Another example:

use wordnik_list::word_iterator;

// Collect list of every 2-letter word
let vec: Vec<&str> = word_iterator().filter(|word| word.len() == 2).collect();
println!("List of every 2-letter word: {:?}", vec);

Functions§

word_exists
Accepts a lowercase ASCII encoded string reference and returns whether it is a valid word or not. Note: this will always fail if there are any characters outside of the lowercase range [a-z].
word_iterator
Returns an iterator over every valid word registered in the Wordnik API. Yield order is not guaranteed
word_iterator_by_len
Returns an iterator of every valid word with a given length registered in the Wordnik API.
word_range
Returns an iterator of the valid words in the range [begin, end). Not guaranteed to return them in any particular order.