use super::{Entries, IterMut2, KeysMut, Slot, VecMap};
use core::borrow::Borrow;
pub trait MutableKeys: private::Sealed {
type Key;
type Value;
fn get_full_mut2<Q>(&mut self, key: &Q) -> Option<(usize, &mut Self::Key, &mut Self::Value)>
where
Self::Key: Borrow<Q>,
Q: Eq + ?Sized;
fn get_index_mut2(&mut self, index: usize) -> Option<(&mut Self::Key, &mut Self::Value)>;
fn retain2<F>(&mut self, f: F)
where
F: FnMut(&mut Self::Key, &mut Self::Value) -> bool;
fn iter_mut2(&mut self) -> IterMut2<'_, Self::Key, Self::Value>;
fn keys_mut(&mut self) -> KeysMut<'_, Self::Key, Self::Value>;
}
impl<K, V> MutableKeys for VecMap<K, V> {
type Key = K;
type Value = V;
fn get_full_mut2<Q>(&mut self, key: &Q) -> Option<(usize, &mut K, &mut V)>
where
K: Borrow<Q>,
Q: Eq + ?Sized,
{
self.get_index_of(key).map(|index| {
let (key, value) = self.base[index].muts();
(index, key, value)
})
}
fn get_index_mut2(&mut self, index: usize) -> Option<(&mut K, &mut V)> {
self.base.get_mut(index).map(Slot::muts)
}
fn retain2<F>(&mut self, mut f: F)
where
F: FnMut(&mut K, &mut V) -> bool,
{
self.base.retain_mut(|slot| {
let (key, value) = slot.muts();
f(key, value)
});
}
fn iter_mut2(&mut self) -> IterMut2<'_, K, V> {
IterMut2::new(self.as_entries_mut())
}
fn keys_mut(&mut self) -> KeysMut<'_, K, V> {
KeysMut::new(self.as_entries_mut())
}
}
mod private {
pub trait Sealed {}
impl<K, V> Sealed for super::VecMap<K, V> {}
}