mithril_persistence/sqlite/
source_alias.rs1use std::collections::{hash_map::Iter, HashMap};
2
3#[derive(Debug, Default, Clone)]
10pub struct SourceAlias {
11 aliases: HashMap<String, String>,
13}
14
15impl SourceAlias {
16 pub fn new(aliases: &[(&str, &str)]) -> Self {
18 Self {
19 aliases: aliases
20 .iter()
21 .map(|(name, alias)| (name.to_string(), alias.to_string()))
22 .collect(),
23 }
24 }
25
26 pub fn get_iterator(&self) -> Iter<'_, String, String> {
28 self.aliases.iter()
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35
36 #[test]
37 fn simple_source_alias() {
38 let source_alias = SourceAlias::new(&[("first", "one"), ("second", "two")]);
39 let mut fields = "first.one, second.two".to_string();
40
41 for (alias, source) in source_alias.get_iterator() {
42 fields = fields.replace(alias, source);
43 }
44 assert_eq!("one.one, two.two".to_string(), fields);
45 }
46}