engish 0.3.9

A language utility for sampling and building words.
Documentation
use serde::{Deserialize, Serialize};
use std::fmt::Display;

/// Data for a letter. As the letter will be stored in a hashmap, we don't actually need to store the actual letter here!
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Letter {
    /// How often this letter appears in the given language set.
    pub frequency: f32,
    /// Any digraphs that start with this letter.
    pub digraphs: Vec<DigraphPair>,
}

impl Display for Letter {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        let digraph_string = self.digraphs.iter().map(|d| d.letter).collect::<String>();

        return write!(
            f,
            "frequency: {}, digraphs: {}",
            self.frequency, digraph_string
        );
    }
}

/// Represents the paired part of a digraph.
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct DigraphPair {
    /// The letter that ends the digraph.
    pub letter: char,
    /// How often this digraph appears in the given language set.
    pub frequency: f32,
}