use std::collections::HashMap;
use std::hash::Hash;
pub trait Getter {
type Index;
type Item: ?Sized;
fn get(&self, index: &Self::Index) -> Option<&Self::Item>;
}
pub trait GetterMut: Getter {
fn get_mut(&mut self, index: &Self::Index) -> Option<&mut Self::Item>;
}
impl<T> Getter for &[T] {
type Index = usize;
type Item = T;
fn get(&self, index: &Self::Index) -> Option<&Self::Item> {
<[T]>::get(self, *index)
}
}
impl<T> Getter for &mut [T] {
type Index = usize;
type Item = T;
fn get(&self, index: &Self::Index) -> Option<&Self::Item> {
<[T]>::get(self, *index)
}
}
impl<T> GetterMut for &mut [T] {
fn get_mut(&mut self, index: &Self::Index) -> Option<&mut Self::Item> {
<[T]>::get_mut(self, *index)
}
}
impl<K, V> Getter for HashMap<K, V>
where
K: Hash + Eq,
{
type Index = K;
type Item = V;
fn get(&self, index: &Self::Index) -> Option<&Self::Item> {
HashMap::get(self, index)
}
}
impl<K, V> GetterMut for HashMap<K, V>
where
K: Hash + Eq,
{
fn get_mut(&mut self, index: &Self::Index) -> Option<&mut Self::Item> {
HashMap::get_mut(self, index)
}
}