ligen_utils/mapper/
mod.rs1use std::hash::Hash;
2use bimap::BiMap;
3
4pub struct LanguageMap<T>
5where T: Eq + Hash
6{
7 left: String,
8 right: String,
9 map: BiMap<T, T>
10}
11
12impl<T> LanguageMap<T>
13where T: Eq + Hash
14{
15 pub fn new(left: impl Into<String>, right: impl Into<String>) -> Self {
16 let left = left.into();
17 let right = right.into();
18 let map = Default::default();
19 Self { left, right, map }
20 }
21
22 pub fn insert(&mut self, left: impl Into<T>, right: impl Into<T>) {
23 self.map.insert(left.into(), right.into());
24 }
25
26 pub fn get(&self, language: impl PartialEq<String>, value: &T) -> Option<&T> {
27 if language == self.left {
28 self.map.get_by_left(value)
29 } else if language == self.right {
30 self.map.get_by_right(value)
31 } else {
32 None
33 }
34 }
35}