use std::{
collections::{BTreeMap, HashMap},
hash::Hash,
};
use crate::redaction::{redact::RedactableMapper, traits::RedactableWithMapper};
impl<K, V, S> RedactableWithMapper for HashMap<K, V, S>
where
K: Hash + Eq,
V: RedactableWithMapper,
S: std::hash::BuildHasher + Clone,
{
fn redact_with<M: RedactableMapper>(self, mapper: &M) -> Self {
let hasher = self.hasher().clone();
let mut result = HashMap::with_capacity_and_hasher(self.len(), hasher);
result.extend(self.into_iter().map(|(k, v)| (k, v.redact_with(mapper))));
result
}
}
impl<K, V> RedactableWithMapper for BTreeMap<K, V>
where
K: Ord,
V: RedactableWithMapper,
{
fn redact_with<M: RedactableMapper>(self, mapper: &M) -> Self {
self.into_iter()
.map(|(k, v)| (k, v.redact_with(mapper)))
.collect()
}
}