// codesnip-guard: container #[cfg_attr(any(),rustfmt::skip)]pub use self::container::{Container,ContainerEntry};#[cfg_attr(any(),rustfmt::skip)]mod container{use std::{cmp::Ord,collections::{BTreeMap,HashMap,btree_map,hash_map},hash::{BuildHasher,Hash},iter::FusedIterator};pub trait Container{type Key;type Value;type Entry<'a>:ContainerEntry<'a,Key=Self::Key,Value=Self::Value>where Self:'a,Self::Key:'a,Self::Value:'a;type Iter<'a>:Iteratorwhere Self:'a,Self::Key:'a,Self::Value:'a;type Drain<'a>:Iteratorwhere Self:'a,Self::Key:'a,Self::Value:'a;fn get(&self,key:&Self::Key)->Option<&Self::Value>;fn get_mut(&mut self,key:&Self::Key)->Option<&mut Self::Value>;fn insert(&mut self,key:Self::Key,value:Self::Value)->Option;fn remove(&mut self,key:&Self::Key)->Option;fn entry(&mut self,key:Self::Key)->Self::Entry<'_>;fn iter(&self)->Self::Iter<'_>;fn drain(&mut self)->Self::Drain<'_>;}pub trait ContainerEntry<'a>{type Key:'a;type Value:'a;fn or_default(self)->&'a mut Self::Value where Self::Value:Default;fn or_insert(self,default:Self::Value)->&'a mut Self::Value;fn or_insert_with(self,default:F)->&'a mut Self::Value where F:FnOnce()->Self::Value;fn or_insert_with_key(self,default:F)->&'a mut Self::Value where F:FnOnce(&Self::Key)->Self::Value;fn key(&self)->&Self::Key;fn and_modify(self,f:F)->Self where F:FnOnce(&mut Self::Value);}#[derive(Debug)]pub struct BTreeMapDrain<'a,K,V>{inner:&'a mut BTreeMap}implContainer for BTreeMapwhere K:Ord{type Key=K;type Value=V;type Entry<'a>=btree_map::Entry<'a,K,V>where K:'a,V:'a;type Iter<'a>=btree_map::Iter<'a,K,V>where K:'a,V:'a;type Drain<'a>=BTreeMapDrain<'a,K,V>where K:'a,V:'a;fn get(&self,key:&Self::Key)->Option<&Self::Value>{self.get(key)}fn get_mut(&mut self,key:&Self::Key)->Option<&mut Self::Value>{self.get_mut(key)}fn insert(&mut self,key:Self::Key,value:Self::Value)->Option{self.insert(key,value)}fn remove(&mut self,key:&Self::Key)->Option{self.remove(key)}fn entry(&mut self,key:Self::Key)->Self::Entry<'_>{self.entry(key)}fn iter(&self)->Self::Iter<'_>{self.iter()}fn drain(&mut self)->Self::Drain<'_>{BTreeMapDrain{inner:self}}}implIterator for BTreeMapDrain<'_,K,V>where K:Ord{type Item=(K,V);fn next(&mut self)->Option{self.inner.pop_first()}}implDoubleEndedIterator for BTreeMapDrain<'_,K,V>where K:Ord{fn next_back(&mut self)->Option{self.inner.pop_last()}}implExactSizeIterator for BTreeMapDrain<'_,K,V>where K:Ord{fn len(&self)->usize{self.inner.len()}}implFusedIterator for BTreeMapDrain<'_,K,V>where K:Ord{}impl<'a,K,V>ContainerEntry<'a>for btree_map::Entry<'a,K,V>where K:'a+Ord,V:'a{type Key=K;type Value=V;fn or_default(self)->&'a mut Self::Value where Self::Value:Default{self.or_default()}fn or_insert(self,default:Self::Value)->&'a mut Self::Value{self.or_insert(default)}fn or_insert_with(self,default:F)->&'a mut Self::Value where F:FnOnce()->Self::Value{self.or_insert_with(default)}fn or_insert_with_key(self,default:F)->&'a mut Self::Value where F:FnOnce(&Self::Key)->Self::Value{self.or_insert_with_key(default)}fn key(&self)->&Self::Key{self.key()}fn and_modify(self,f:F)->Self where F:FnOnce(&mut Self::Value){self.and_modify(f)}}implContainer for HashMapwhere K:Eq+Hash,S:BuildHasher{type Key=K;type Value=V;type Entry<'a>=hash_map::Entry<'a,K,V>where S:'a,K:'a,V:'a;type Iter<'a>=hash_map::Iter<'a,K,V>where S:'a,K:'a,V:'a;type Drain<'a>=hash_map::Drain<'a,K,V>where S:'a,K:'a,V:'a;fn get(&self,key:&Self::Key)->Option<&Self::Value>{self.get(key)}fn get_mut(&mut self,key:&Self::Key)->Option<&mut Self::Value>{self.get_mut(key)}fn insert(&mut self,key:Self::Key,value:Self::Value)->Option{self.insert(key,value)}fn remove(&mut self,key:&Self::Key)->Option{self.remove(key)}fn entry(&mut self,key:Self::Key)->Self::Entry<'_>{self.entry(key)}fn iter(&self)->Self::Iter<'_>{self.iter()}fn drain(&mut self)->Self::Drain<'_>{self.drain()}}impl<'a,K,V>ContainerEntry<'a>for hash_map::Entry<'a,K,V>where K:'a+Eq+Hash,V:'a{type Key=K;type Value=V;fn or_default(self)->&'a mut Self::Value where Self::Value:Default{self.or_default()}fn or_insert(self,default:Self::Value)->&'a mut Self::Value{self.or_insert(default)}fn or_insert_with(self,default:F)->&'a mut Self::Value where F:FnOnce()->Self::Value{self.or_insert_with(default)}fn or_insert_with_key(self,default:F)->&'a mut Self::Value where F:FnOnce(&Self::Key)->Self::Value{self.or_insert_with_key(default)}fn key(&self)->&Self::Key{self.key()}fn and_modify(self,f:F)->Self where F:FnOnce(&mut Self::Value){self.and_modify(f)}}}