use std::{collections::HashMap, convert::Infallible};
use crate::formatter::Taggable;
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct FormatTable {
table: HashMap<String, String>,
}
impl FormatTable {
pub fn new() -> Self {
Self {
table: HashMap::new(),
}
}
pub fn add_entry(&mut self, key: impl Into<String>, value: impl Into<String>) {
self.table
.insert(key.into().to_ascii_lowercase(), value.into());
}
pub fn add_table(&mut self, table: impl IntoIterator<Item = (String, String)>) {
self.table.extend(table);
}
pub fn extend_from_taggable<T: Taggable>(&mut self, from: &T) -> Result<(), T::Err> {
from.fill_table(self)
}
pub fn table(&self) -> &HashMap<String, String> {
&self.table
}
}
impl Taggable for FormatTable {
type Err = Infallible;
fn fill_table(&self, table: &mut FormatTable) -> Result<(), Infallible> {
table.table.extend(self.table.clone());
Ok(())
}
}