pub(crate) mod handle;
use handle::DictionaryHandle;
const MAX_LEN: usize = 8000;
pub struct Dictionary {
handle: DictionaryHandle,
}
impl Dictionary {
pub fn open(name: &str) -> Self {
let handle = match DictionaryHandle::open(name) {
Ok(h) if h.is_valid() => h,
Ok(_) => panic!("could not open dictionary `{}`", name),
Err(e) => panic!("could not open dictionary `{}`: {}", name, e),
};
Self { handle }
}
pub fn get(&self, key: &str) -> Option<String> {
self.handle
.get(key, MAX_LEN)
.unwrap_or_else(|e| panic!("lookup for key `{}` failed: {}", key, e))
}
pub fn contains(&self, key: &str) -> bool {
self.handle
.contains(key)
.unwrap_or_else(|e| panic!("lookup for key `{}` failed: {}", key, e))
}
}