#![cfg_attr(
feature = "std",
doc = r#"
```rust
use std::collections::HashMap;
use isx::IsEmpty;
fn assert<V: IsEmpty>(v: V) {
assert!(v.is_empty());
}
fn test() {
assert(String::default());
assert(Vec::<String>::new());
assert(HashMap::<String,String>::new())
}
```
You can also implement [`IsEmpty`] for your own type using a derive:
```rust
use isx_macros::IsEmpty;
#[derive(IsEmpty)]
struct MyStruct {
foo: String,
bar: Vec<String>,
}
```
"#
)]
#[cfg(feature = "alloc")]
mod alloc;
#[cfg(feature = "bytes")]
mod bytes;
#[cfg(feature = "serde_json")]
mod serde_json;
#[cfg(feature = "std")]
mod std;
pub use isx_macros::IsEmpty;
pub trait IsEmpty {
fn is_empty(&self) -> bool;
}
#[allow(unused_macros)]
macro_rules! default_impl {
($n:ident) => {
impl $crate::IsEmpty for $n {
fn is_empty(&self) -> bool {
<$n>::is_empty(self)
}
}
};
($n:ident<$t:ident>) => {
impl<$t> $crate::IsEmpty for $n<$t> {
fn is_empty(&self) -> bool {
<$n<$t>>::is_empty(self)
}
}
};
($n:ident<$($t:ident),+>) => {
impl<$($t),+> $crate::IsEmpty for $n<$($t),+> {
fn is_empty(&self) -> bool {
<$n<$($t),+>>::is_empty(self)
}
}
};
}
#[allow(unused_imports)]
pub(crate) use default_impl;
impl IsEmpty for &str {
fn is_empty(&self) -> bool {
str::is_empty(self)
}
}
impl<T> IsEmpty for Option<T> {
fn is_empty(&self) -> bool {
self.is_none()
}
}
impl<T> IsEmpty for [T] {
fn is_empty(&self) -> bool {
<[T]>::is_empty(self)
}
}
impl<const N: usize, T> IsEmpty for [T; N] {
fn is_empty(&self) -> bool {
<[T]>::is_empty(self)
}
}
impl IsEmpty for () {
fn is_empty(&self) -> bool {
true
}
}