use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
pub trait IsEmpty {
fn is_empty(&self) -> bool;
}
macro_rules! simple_is_empty {
($type:ty) => {
impl $crate::is_empty::IsEmpty for $type {
fn is_empty(&self) -> bool {
<$type>::is_empty(self)
}
}
};
($type:ident; $($args:tt)*) => {
impl<$($args)*> $crate::is_empty::IsEmpty for $type<$($args)*> {
fn is_empty(&self) -> bool {
$type::is_empty(self)
}
}
};
}
simple_is_empty!(BinaryHeap; T);
simple_is_empty!(BTreeMap; K, V);
simple_is_empty!(BTreeSet; T);
simple_is_empty!(HashMap; K, V);
simple_is_empty!(HashSet; T);
simple_is_empty!(LinkedList; T);
simple_is_empty!(Vec; T);
simple_is_empty!(VecDeque; T);
simple_is_empty!(String);
impl IsEmpty for &str {
fn is_empty(&self) -> bool {
str::is_empty(self)
}
}
impl<T> IsEmpty for &[T] {
fn is_empty(&self) -> bool {
<[T]>::is_empty(self)
}
}
impl<T> IsEmpty for Option<T>
where
T: IsEmpty,
{
fn is_empty(&self) -> bool {
self.as_ref().map(IsEmpty::is_empty).unwrap_or(true)
}
}
impl<T, E> IsEmpty for Result<T, E>
where
T: IsEmpty,
{
fn is_empty(&self) -> bool {
self.as_ref().map(IsEmpty::is_empty).unwrap_or(true)
}
}