mod collection_pattern;
pub use collection_pattern::CollectionPattern;
use crate::assertions::collection::*;
use crate::core::assert::ChainableAssert;
use std::collections::{LinkedList, VecDeque};
use std::fmt::Debug;
pub trait ShouldCollection<C: Debug>
where
C: Collection,
{
fn contain<P>(self, right: P) -> ChainableAssert<ContainCollection<C, P>>
where
P: CollectionPattern<C>;
fn be_empty(self) -> ChainableAssert<BeEmptyCollection<C>>;
}
pub trait Collection {
type Item: PartialEq;
fn is_empty(&self) -> bool;
fn contains(&self, item: &Self::Item) -> bool;
}
impl<T> Collection for Vec<T>
where
T: PartialEq<T>,
{
type Item = T;
fn is_empty(&self) -> bool {
self.is_empty()
}
fn contains(&self, item: &Self::Item) -> bool {
(self as &[_]).contains(item)
}
}
impl<T> Collection for VecDeque<T>
where
T: PartialEq<T>,
{
type Item = T;
fn is_empty(&self) -> bool {
self.is_empty()
}
fn contains(&self, item: &Self::Item) -> bool {
VecDeque::contains(self, item)
}
}
impl<T> Collection for LinkedList<T>
where
T: PartialEq<T>,
{
type Item = T;
fn is_empty(&self) -> bool {
self.is_empty()
}
fn contains(&self, item: &Self::Item) -> bool {
LinkedList::contains(self, item)
}
}