use super::*;
pub trait CollectionSequenceCommon<T,Idx> : TryGet<Idx, Output=T> + TryGetMut<T, Output=T> + GetManyMut<T, Output=T> + Length {}
pub trait CollectionSequence<T,Idx> : CollectionSequenceCommon<T,Idx> + Clear {}
impl<T,Idx> CollectionSequenceCommon<T,Idx> for [T] where Self: TryGet<Idx,Output = T> + TryGetMut<T, Output=T> + GetManyMut<T, Output=T> {}
impl<T,Idx, const N:usize> CollectionSequenceCommon<T,Idx> for [T;N] where Self: TryGet<Idx,Output = T> + TryGetMut<T, Output=T> + GetManyMut<T, Output=T> {}
impl<T,Idx> CollectionSequenceCommon<T,Idx> for Vec<T> where Self: TryGet<Idx,Output = T> + TryGetMut<T, Output=T> + GetManyMut<T, Output=T> {}
impl<T,Idx> CollectionSequence<T,Idx> for Vec<T> where Self: TryGet<Idx,Output = T> + TryGetMut<T, Output=T> + GetManyMut<T, Output=T> {}
impl<T,Idx> CollectionSequenceCommon<T,Idx> for LinkedList<T> where Self: TryGet<Idx,Output = T> + TryGetMut<T, Output=T> + GetManyMut<T, Output=T> {}
impl<T,Idx> CollectionSequence<T,Idx> for LinkedList<T> where Self: TryGet<Idx,Output = T> + TryGetMut<T, Output=T> + GetManyMut<T, Output=T> {}
pub trait CollectionSet<Q,K> : CollectionMap<Q,K,()>
where K: Borrow<Q>, Q: ?Sized
{}
impl<Q,K,S> CollectionSet<Q,K> for S where S: CollectionMap<Q,K,()>, K: Borrow<Q>, Q: ?Sized {}
pub trait CollectionMap<Q,K,V=()> : TryInsert<K,V> + Remove<Q> + Length + Clear
where K: Borrow<Q>, Q: ?Sized
{}
impl<Q,K,V,S> CollectionMap<Q,K,V> for HashMap<K,V,S>
where
Self: TryInsert<K,V> + Remove<Q> + Length + Clear,
K: Borrow<Q>, Q: ?Sized
{}
impl<Q,K,V> CollectionMap<Q,K,V> for BTreeMap<K,V>
where
Self: TryInsert<K,V> + Remove<Q> + Length + Clear,
K: Borrow<Q>, Q: ?Sized
{}
impl<Q,K,S> CollectionMap<Q,K> for HashSet<K,S>
where
Self: TryInsert<K> + Remove<Q> + Length + Clear,
K: Borrow<Q>, Q: ?Sized
{}
impl<Q,K> CollectionMap<Q,K> for BTreeSet<K>
where
Self: TryInsert<K> + Remove<Q> + Length + Clear,
K: Borrow<Q>, Q: ?Sized
{}
pub trait Push<T>
{
type Output;
fn push(&mut self, value: T) -> Self::Output;
}
pub trait Pop<T>
{
fn pop(&mut self) -> Option<T>;
}
pub trait TryPop<T> : Pop<T>
{
type Error;
fn try_pop(&mut self) -> Result<T, Self::Error>;
}
pub trait TryInsert<K,V=()> : Insert<K,V>
{
type Error;
fn try_insert(&mut self, key: K, value: V) -> Result<Self::Output, Self::Error>;
}
pub trait Insert<K,V=()>
{
type Output;
fn insert(&mut self, key: K, value: V) -> Option<Self::Output>;
}
impl<T> Push<T> for Vec<T>
{
type Output = usize;
#[inline(always)]
fn push(&mut self, value : T) -> Self::Output
{
let l = self.len();
self.push(value);
l
}
}
impl<T> Push<T> for VecDeque<T>
{
type Output = usize;
fn push(&mut self, value : T) -> Self::Output
{
let l = self.len();
self.push_back(value);
l
}
}
impl<T> Push<T> for LinkedList<T>
{
type Output = ();
fn push(&mut self, value : T) -> Self::Output {
self.push_back(value);
}
}
impl Push<char> for String
{
type Output = ();
fn push(&mut self, value : char) -> Self::Output {
self.push(value);
}
}
impl<'b> Push<&'b OsStr> for OsString
{
type Output = ();
fn push(&mut self, value : &'b OsStr) -> Self::Output {
self.push(value);
}
}
impl<T> TryPop<T> for Vec<T>
{
type Error=(); fn try_pop(&mut self) -> Result<T, Self::Error> { self.pop().ok_or(()) }
}
impl<T> Pop<T> for Vec<T>
{
fn pop(&mut self) -> Option<T> { self.pop() }
}
impl<T> TryPop<T> for VecDeque<T>
{
type Error=(); fn try_pop(&mut self) -> Result<T, Self::Error> { self.pop_back().ok_or(()) }
}
impl<T> Pop<T> for VecDeque<T>
{
fn pop(&mut self) -> Option<T> { self.pop_back() }
}
impl<T> TryPop<T> for LinkedList<T>
{
type Error=(); fn try_pop(&mut self) -> Result<T, Self::Error> { self.pop_back().ok_or(()) }
}
impl<T> Pop<T> for LinkedList<T>
{
fn pop(&mut self) -> Option<T> { self.pop_back() }
}