Skip to main content

len

Function len 

Source
pub fn len<E>(expected: E) -> LenMatcher<E>
Expand description

Matches a container whose number of elements matches expected.

This matches against a container over which one can iterate. This includes the standard Rust containers, arrays, and slices. More precisely, the actual type must implement IntoIterator.

let array = [1,2,3];
verify_that!(array, len(eq(3)))?;
let vec = vec![1,2,3];
verify_that!(vec, len(eq(3)))?;
let slice = vec.as_slice();
verify_that!(*slice, len(eq(3)))?;

The parameter expected can be any integer numeric matcher.

let vec = vec![1,2,3];
verify_that!(vec, len(gt(1)))?;