pub struct StrComparison<'a, TLeft, TRight> where
    TLeft: ?Sized,
    TRight: ?Sized
{ /* private fields */ }
Expand description

A comparison of two strings.

In contrast to Comparison, which uses the core::fmt::Debug representation, StrComparison uses the string values directly, resulting in multi-line output for multiline strings.

use pretty_assertions::StrComparison;

print!("{}", StrComparison::new("foo\nbar", "foo\nbaz"));

Value type bounds

Any value that can be referenced as a str via AsRef may be used:

use pretty_assertions::StrComparison;

#[derive(PartialEq)]
struct MyString(String);

impl AsRef<str> for MyString {
    fn as_ref(&self) -> &str {
        &self.0
    }
}

print!(
    "{}",
    StrComparison::new(
        &MyString("foo\nbar".to_owned()),
        &MyString("foo\nbaz".to_owned()),
    ),
);

The values may have different types, although in practice they are usually the same.

Implementations

Store two values to be compared in future.

Expensive diffing is deferred until calling Debug::fmt.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.