use super::{RawContainer, RawEntry};
pub trait RawStore<K, V>: RawContainer<Item = V> {
private!();
}
pub trait Store<K, V>: RawStore<K, V> {
type Entry<'a>: RawEntry<'a, Key = K, Value = V>
where
Self: 'a;
fn entry(&mut self, key: K) -> Self::Entry<'_>;
fn insert(&mut self, key: K, value: V) -> Option<V>;
}
pub trait StoreIter<K, V> {
type Item<'a, _K, _V>
where
Self: 'a;
type Iter<'a>: Iterator<Item = Self::Item<'a, K, V>>
where
Self: 'a;
fn iter(&self) -> Self::Iter<'_>;
}
#[cfg(feature = "alloc")]
mod impl_alloc {
use super::*;
use alloc::collections::btree_map::{self, BTreeMap};
impl<K, V> RawStore<K, V> for BTreeMap<K, V>
where
K: Ord,
{
seal!();
}
impl<K, V> Store<K, V> for BTreeMap<K, V>
where
K: Ord,
{
type Entry<'a>
= btree_map::Entry<'a, K, V>
where
Self: 'a;
fn entry(&mut self, key: K) -> Self::Entry<'_> {
self.entry(key)
}
fn insert(&mut self, key: K, value: V) -> Option<V> {
self.insert(key, value)
}
}
}
#[cfg(feature = "std")]
mod impl_std {
use super::*;
use core::hash::{BuildHasher, Hash};
use std::collections::hash_map::{self, HashMap};
impl<K, V, S> RawStore<K, V> for HashMap<K, V, S>
where
K: Eq + Hash,
S: BuildHasher,
{
seal!();
}
impl<K, V, S> Store<K, V> for HashMap<K, V, S>
where
K: Eq + Hash,
S: BuildHasher,
{
type Entry<'a>
= hash_map::Entry<'a, K, V>
where
Self: 'a;
fn entry(&mut self, key: K) -> Self::Entry<'_> {
self.entry(key)
}
fn insert(&mut self, key: K, value: V) -> Option<V> {
self.insert(key, value)
}
}
}