IsEmpty

Trait IsEmpty 

Source
pub trait IsEmpty {
    // Required method
    fn is_empty(&self) -> bool;
}
Expand description

Used to determine if a collection, or Option<T> or Result<T, E> (where T implements IsEmpty) is empty.

IsEmpty is implemented for the standard collections, and more.

Required Methods§

Source

fn is_empty(&self) -> bool

Returns true if it is empty.

Implementations on Foreign Types§

Source§

impl IsEmpty for &str

Source§

fn is_empty(&self) -> bool

Source§

impl IsEmpty for String

Source§

fn is_empty(&self) -> bool

Source§

impl IsEmpty for QueryMap

Source§

fn is_empty(&self) -> bool

Source§

impl IsEmpty for Map<String, Value>

Source§

fn is_empty(&self) -> bool

Source§

impl<K, V> IsEmpty for BTreeMap<K, V>

Source§

fn is_empty(&self) -> bool

Source§

impl<K, V> IsEmpty for HashMap<K, V>

Source§

fn is_empty(&self) -> bool

Source§

impl<T> IsEmpty for &[T]

Source§

fn is_empty(&self) -> bool

Source§

impl<T> IsEmpty for Option<T>
where T: IsEmpty,

Source§

fn is_empty(&self) -> bool

Returns true if Option is None or Some with an empty IsEmpty, otherwise, false.

§Examples
let some: Option<Vec<&str>> = Some(vec!["a", "b", "c"]);
assert_eq!(false, some.is_empty());
let some_empty: Option<Vec<&str>> = Some(vec![]);
assert_eq!(true, some_empty.is_empty());
let none: Option<Vec<&str>> = None;
assert_eq!(true, none.is_empty());

Works nested:

let some_some: Option<Option<Vec<&str>>> = Some(Some(vec!["a", "b", "c"]));
assert_eq!(false, some_some.is_empty());
let some_some_empty: Option<Option<Vec<&str>>> = Some(Some(vec![]));
assert_eq!(true, some_some_empty.is_empty());
let some_none: Option<Option<Vec<&str>>> = Some(None);
assert_eq!(true, some_none.is_empty());

Works mixed:

let ok_some_empty: Result<Option<Vec<&str>>, &str> = Ok(Some(vec![]));
assert_eq!(true, ok_some_empty.is_empty());
Source§

impl<T> IsEmpty for &T
where T: IsEmpty,

Source§

fn is_empty(&self) -> bool

Source§

impl<T> IsEmpty for BinaryHeap<T>

Source§

fn is_empty(&self) -> bool

Source§

impl<T> IsEmpty for BTreeSet<T>

Source§

fn is_empty(&self) -> bool

Source§

impl<T> IsEmpty for LinkedList<T>

Source§

fn is_empty(&self) -> bool

Source§

impl<T> IsEmpty for VecDeque<T>

Source§

fn is_empty(&self) -> bool

Source§

impl<T> IsEmpty for Vec<T>

Source§

fn is_empty(&self) -> bool

Source§

impl<T> IsEmpty for HashSet<T>

Source§

fn is_empty(&self) -> bool

Source§

impl<T, E> IsEmpty for Result<T, E>
where T: IsEmpty,

Source§

fn is_empty(&self) -> bool

Returns true if Result is Some with an empty IsEmpty, otherwise, false.

§Examples
let ok: Result<Vec<&str>, &str> = Ok(vec!["a", "b", "c"]);
assert_eq!(false, ok.is_empty());
let ok: Result<Vec<&str>, &str> = Ok(vec![]);
assert_eq!(true, ok.is_empty());
let err: Result<Vec<&str>, &str> = Err("nope");
assert_eq!(false, err.is_empty());

Works nested:

let ok_ok: Result<Result<Vec<&str>, &str>, &str> = Ok(Ok(vec!["a", "b", "c"]));
assert_eq!(false, ok_ok.is_empty());
let ok_ok_empty: Result<Result<Vec<&str>, &str>, &str> = Ok(Ok(vec![]));
assert_eq!(true, ok_ok_empty.is_empty());
let ok_err: Result<Result<Vec<&str>, &str>, &str> = Ok(Err("none"));
assert_eq!(false, ok_err.is_empty());

Works mixed:

let ok_some_empty: Result<Option<Vec<&str>>, &str> = Ok(Some(vec![]));
assert_eq!(true, ok_some_empty.is_empty());

Implementors§