lunar_lib/formatter/
format_table.rs1use std::collections::HashMap;
2
3use crate::formatter::Taggable;
4
5#[derive(Debug, Clone, PartialEq, Eq, Default)]
7pub struct FormatTable {
8 table: HashMap<String, String>,
9}
10
11impl FormatTable {
12 pub fn new() -> Self {
14 Self {
15 table: HashMap::new(),
16 }
17 }
18
19 pub fn add_entry(&mut self, key: impl Into<String>, value: impl Into<String>) {
21 self.table
22 .insert(key.into().to_ascii_lowercase(), value.into());
23 }
24
25 pub fn add_table(&mut self, table: impl IntoIterator<Item = (String, String)>) {
27 self.table.extend(table);
28 }
29
30 pub fn extend<T: Taggable>(&mut self, from: &T) {
32 from.fill_table(self);
33 }
34
35 pub fn table(&self) -> &HashMap<String, String> {
37 &self.table
38 }
39}
40
41impl Taggable for FormatTable {
42 fn fill_table(&self, table: &mut FormatTable) {
43 table.table.extend(self.table.clone());
44 }
45}