readsight 1.0.2

Multilingual readability library — 86 languages, 17 formulas, TeX-based syllable counting via the Frank M. Liang algorithm.
Documentation
//! Hyphenation exceptions (explicit overrides from `\hyphenation{}` blocks).

use std::collections::HashMap;

/// A single explicit hyphenation override.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HyphenationOverride {
    /// The word, lowercased with hyphens removed.
    pub word: String,
    /// The hyphenated form (lowercased, with `-` separators).
    pub hyphenated: String,
}

impl HyphenationOverride {
    /// Construct an override.
    pub fn new(word: impl Into<String>, hyphenated: impl Into<String>) -> Self {
        HyphenationOverride {
            word: word.into(),
            hyphenated: hyphenated.into(),
        }
    }
}

/// Collection of hyphenation overrides keyed by the bare word.
#[derive(Debug, Default, Clone)]
pub struct HyphenationExceptionsCollection {
    exceptions: HashMap<String, String>,
}

impl HyphenationExceptionsCollection {
    /// Create an empty collection.
    pub fn new() -> Self {
        Self::default()
    }

    /// Add an override.
    pub fn add(&mut self, exception: HyphenationOverride) {
        self.exceptions.insert(exception.word, exception.hyphenated);
    }

    /// Whether an override exists for `word`.
    pub fn has(&self, word: &str) -> bool {
        self.exceptions.contains_key(word)
    }

    /// The hyphenated form for `word`, if present.
    pub fn get(&self, word: &str) -> Option<&str> {
        self.exceptions.get(word).map(|s| s.as_str())
    }

    /// Number of overrides.
    pub fn count(&self) -> usize {
        self.exceptions.len()
    }

    /// Whether the collection is empty.
    pub fn is_empty(&self) -> bool {
        self.exceptions.is_empty()
    }
}