extern crate alloc;
use alloc::{
collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque},
string::String,
vec::Vec,
};
use super::IsEmpty;
impl<T> IsEmpty for &T
where
T: IsEmpty,
{
fn is_empty(&self) -> bool {
IsEmpty::is_empty(*self)
}
}
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!(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(false)
}
}