use std::{
collections::{hash_map::IntoIter, HashMap},
fmt::Display,
ops::{Index, IndexMut},
};
use crate::Document;
#[derive(Clone, PartialEq, Debug)]
pub struct DocumentMap(pub(crate) HashMap<String, Document>);
impl<'a, Str> Index<Str> for DocumentMap
where
Str: Display,
{
type Output = Document;
fn index(&self, index: Str) -> &Self::Output {
&self.0[index.to_string().as_str()]
}
}
impl<'a, Str> IndexMut<Str> for DocumentMap
where
Str: Display,
{
fn index_mut(&mut self, index: Str) -> &mut Self::Output {
self.0.get_mut(index.to_string().as_str()).unwrap()
}
}
impl<'a> IntoIterator for DocumentMap {
type Item = (String, Document);
type IntoIter = IntoIter<String, Document>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}