verba 0.5.1

A library for working with Latin words.
Documentation
use std::fmt;

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Number {
    Singular,
    Plural,
}

impl fmt::Display for Number {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            Number::Singular => write!(f, "singular"),
            Number::Plural => write!(f, "plural"),
        }
    }
}

/// Takes a stem and a slice of string references to endings and returns a Vec
/// containing the stem appended to each ending. 
/// 
/// # Example
/// 
/// let stem = "part";
/// let endings = ["em", "im"];
/// 
/// assert_eq!(stem_with_endings(stem, &endings), vec!["partem".to_string(), "partim".to_string()]);
// TODO: Remove when crate::adjective is converted over to using SmallVec. 
pub(crate) fn stem_with_endings(stem: &str, endings: &[&str]) -> Vec<String> {
    endings.iter().fold(Vec::new(), |mut acc, ending| {
        acc.push(format!("{}{}", stem, ending));
        acc
    })
}

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    fn test_stem_with_endings() {
        let stem = "part";
        let endings = ["em", "im"];

        assert_eq!(stem_with_endings(stem, &endings), ["partem".to_string(), "partim".to_string()]);
    }
}