inflekt 0.2.0

Inflects input in a bunch of cases
use std::env;

use inflections::case;
use inflections::Inflect;
use inflector::string::pluralize::to_plural;
use inflector::string::singularize::to_singular;

fn main() {
    let args: Vec<String> = env::args().collect();
    let words = args[1..].to_vec();

    for ord_words in inflect_ord(words) {
        print_matrix(inflect_case(ord_words));
    }
}

fn inflect_ord(words: Vec<String>) -> Vec<Vec<String>> {
    let all_singular = words.iter().all(|w| is_singular(w));
    let all_plural = words.iter().all(|w| is_plural(w));

    let mut out: Vec<Vec<String>> = Vec::with_capacity(3);

    if !all_singular {
        let singular = words.iter().map(|w| to_singular(w)).collect();
        out.push(singular);
    }

    if !all_plural {
        let plural = words.iter().map(|w| to_plural(w)).collect();
        out.push(plural);
    }

    out.push(words);

    out
}

fn inflect_case(words: Vec<String>) -> Vec<Vec<String>> {
    let inflections: Vec<fn(&str) -> String> = vec![
        to_all_lower,
        to_all_upper,
        case::to_camel_case,
        case::to_pascal_case,
        case::to_kebab_case,
        case::to_train_case,
        case::to_snake_case,
        case::to_constant_case,
    ];
    let mut out = Vec::with_capacity(inflections.len());
    for i in inflections {
        out.push(words.iter().map(|w| i(w)).collect())
    }
    out
}

fn to_all_lower(word: &str) -> String {
    word.to_camel_case().to_lowercase()
}

fn to_all_upper(word: &str) -> String {
    word.to_camel_case().to_uppercase()
}

fn is_singular(word: &str) -> bool {
    to_singular(word) == word
}

fn is_plural(word: &str) -> bool {
    to_plural(word) == word
}

fn print_matrix(xxs: Vec<Vec<String>>) {
    for xs in xxs {
        println!("{}", xs.join(" "));
    }
}