pub struct Description { /* private fields */ }
Expand description

Helper structure to build better output of Matcher::describe and Matcher::explain_match. This is especially useful with composed matchers and matchers over containers.

It provides simple operations to lazily format lists of strings.

Usage:

let iter: impl Iterator<String> = ...
format!("{}", iter.collect::<Description>().indent().bullet_list())

To construct a Description, use Iterator<Item=String>::collect(). Each element of the collected iterator will be separated by a newline when displayed. The elements may be multi-line, but they will nevertheless be indented consistently.

Note that a newline will only be added between each element, but not after the last element. This makes it simpler to keep Matcher::describe and Matcher::explain_match consistent with simpler Matchers.

They can also be indented, enumerated and or bullet listed if Description::indent, Description::enumerate, or respectively Description::bullet_list has been called.

Implementations§

source§

impl Description

source

pub fn indent(self) -> Self

Indents the lines in elements of this description.

This operation will be performed lazily when self is displayed.

This will indent every line inside each element.

For example:

let description = std::iter::once("A B C\nD E F".to_string()).collect::<Description>();
verify_that!(description.indent(), displays_as(eq("  A B C\n  D E F")))
source

pub fn indent_except_first_line(self) -> Self

Indents the lines in elements of this description except for the first line.

This is similar to Self::indent except that the first line is not indented. This is useful when the first line has already been indented in the output.

For example:

let description = std::iter::once("A B C\nD E F".to_string()).collect::<Description>();
verify_that!(description.indent_except_first_line(), displays_as(eq("A B C\n  D E F")))
source

pub fn bullet_list(self) -> Self

Bullet lists the elements of self.

This operation will be performed lazily when self is displayed.

Note that this will only bullet list each element, not each line in each element.

For instance:

let description = std::iter::once("A B C\nD E F".to_string()).collect::<Description>();
verify_that!(description.bullet_list(), displays_as(eq("* A B C\n  D E F")))
source

pub fn enumerate(self) -> Self

Enumerates the elements of self.

This operation will be performed lazily when self is displayed.

Note that this will only enumerate each element, not each line in each element.

For instance:

let description = std::iter::once("A B C\nD E F".to_string()).collect::<Description>();
verify_that!(description.enumerate(), displays_as(eq("0. A B C\n   D E F")))
source

pub fn len(&self) -> usize

Returns the length of elements.

source

pub fn is_empty(&self) -> bool

Returns whether the set of elements is empty.

Trait Implementations§

source§

impl Debug for Description

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Description

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromIterator<String> for Description

source§

fn from_iter<T>(iter: T) -> Selfwhere T: IntoIterator<Item = String>,

Creates a value from an iterator. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.