Trait AssertEmptiness

Source
pub trait AssertEmptiness {
    // Required methods
    fn is_empty(self) -> Self;
    fn is_not_empty(self) -> Self;
}
Expand description

Assert whether a string, collection or iterator is empty or not.

These assertions are implemented for all types T that implement the trait IsEmptyProperty. This property trait is implemented for string like types and collection like types of the std lib. For example:

  • String, &str, OsString, CString, etc.
  • Vec, array, slice, VecDeque, LinkedList, etc.
  • HashMap, HashSet, BTreeSet, etc.

§Examples

use std::collections::{BTreeSet, HashMap, HashSet, VecDeque};
use asserting::prelude::*;

let some_string = String::new();
assert_that!(some_string).is_empty();

let some_str = "ad praesent aliqua qui";
assert_that!(some_str).is_not_empty();

let some_vec: Vec<String> = vec![];
assert_that!(some_vec).is_empty();

let some_array = [12, 24, 36, 48];
assert_that!(some_array).is_not_empty();

let some_slice: &[_] = &['a', 'b', 'c'][..];
assert_that!(some_slice).is_not_empty();

let some_btree_set = BTreeSet::<i64>::new();
assert_that!(&some_btree_set).is_empty();

let some_dequeue = VecDeque::<String>::new();
assert_that!(some_dequeue).is_empty();

with crate feature std enabled:

use std::collections::{HashMap, HashSet};
use asserting::prelude::*;

let some_set: HashSet<_> = [1, 3, 5, 7, 11, 13, 17, 19].into_iter().collect();
assert_that!(&some_set).is_not_empty();

let some_map: HashMap<String, usize> = HashMap::new();
assert_that!(some_map).is_empty();

Required Methods§

Source

fn is_empty(self) -> Self

Verifies that the subject is empty.

Source

fn is_not_empty(self) -> Self

Verifies that the subject is not empty.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<S, R> AssertEmptiness for Spec<'_, S, R>