Should

Struct Should 

Source
pub struct Should<'a, T> { /* private fields */ }
Expand description

A wrapper type that provides fluent-style assertions for a given value.

Constructed using the Shouldable::should method.

Implementations§

Source§

impl<'a> Should<'a, bool>

Source

pub fn be_true(&self)

Asserts that the value is true.

§Examples
use shoulds::Shouldable;

let value = true;
value.should().be_true();
§Panics

Panics if the actual value is not true.

Source

pub fn be_false(&self)

Asserts that the value is false.

§Examples
use shoulds::Shouldable;

let value = false;
value.should().be_false();
§Panics

Panics if the actual value is not false.

Source§

impl<'a, T> Should<'a, T>
where T: PartialEq + Debug,

Source

pub fn eq(&self, expected: &T)

Asserts that the value is equal to the expected value.

§Examples
use shoulds::Shouldable;

let value = 42;
value.should().eq(&42);
§Panics

Panics if the actual value is not equal to the expected value.

Source§

impl<'a, T> Should<'a, T>
where T: PartialEq + Debug,

Source

pub fn ne(&self, expected: &T)

Asserts that the value is not equal to the expected value.

§Examples
use shoulds::Shouldable;

let value = 42;
value.should().ne(&43);
§Panics

Panics if the actual value is equal to the expected value.

Source§

impl<'a, T> Should<'a, Option<T>>
where T: Debug,

Source

pub fn be_some(&self)

Asserts that the Option is Some.

§Examples
use shoulds::Shouldable;

let value: Option<i32> = Some(42);
value.should().be_some();
§Panics

Panics if the Option is None.

Source

pub fn be_none(&self)

Asserts that the Option is None.

§Examples
use shoulds::Shouldable;

let value: Option<i32> = None;
value.should().be_none();
§Panics

Panics if the Option is Some.

Source§

impl<'a, T, E> Should<'a, Result<T, E>>
where T: Debug, E: Debug,

Source

pub fn be_ok(&self)

Asserts that the Result is Ok.

§Examples
use shoulds::Shouldable;

let result: Result<i32, &str> = Ok(42);
result.should().be_ok();
§Panics

Panics if the Result is an Err.

Source

pub fn be_err(&self)

Asserts that the Result is Err.

§Examples
use shoulds::Shouldable;

let result: Result<i32, &str> = Err("error");
result.should().be_err();
§Panics

Panics if the Result is Ok.

Source§

impl<'a, T> Should<'a, T>

Returns a reference to the underlying value.

This can be useful for writing custom assertions or debugging.

Source

pub fn actual(&self) -> &T

Auto Trait Implementations§

§

impl<'a, T> Freeze for Should<'a, T>

§

impl<'a, T> RefUnwindSafe for Should<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for Should<'a, T>
where T: Sync,

§

impl<'a, T> Sync for Should<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for Should<'a, T>

§

impl<'a, T> UnwindSafe for Should<'a, T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> Shouldable<T> for T

Source§

fn should(&self) -> Should<'_, T>

Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.