Skip to main content

Assert

Struct Assert 

Source
pub struct Assert<T> { /* private fields */ }
Expand description

A wrapper around some object that can be reasoned about.

Use assert_that! to construct an Assert and then use methods to make some Assertion. Assertions can be returned from tests and verified by the test framework.

Implementations§

Source§

impl<T> Assert<T>

Source

pub const fn as_ref(&self) -> Assert<&T>

Converts from &Assert<T> to Assert<&T>.

Source

pub fn as_deref<U>(&self) -> Assert<&U>
where T: Deref<Target = U>,

Converts from Assert<T> or &Assert<T> to Assert<&T::Target> via Deref.

Source

pub fn map<F, U>(self, f: F) -> Assert<U>
where F: FnOnce(T) -> U,

Maps an Assert<T> to an Assert<U> by applying a function to its contained value.

Source

pub fn is_equal_to<U>(self, other: U) -> BinaryAssertion<T, U>
where T: PartialEq<U> + Debug, U: Debug,

Assert that self is equal to other.

Source

pub fn is_not_equal_to<U>(self, other: U) -> BinaryAssertion<T, U>
where T: PartialEq<U> + Debug, U: Debug,

Assert that self is not equal to other.

Source

pub fn is_greater_than<U>(self, other: U) -> BinaryAssertion<T, U>
where T: PartialOrd<U> + Debug, U: Debug,

Assert that self is greater than other.

Source

pub fn is_less_than<U>(self, other: U) -> BinaryAssertion<T, U>
where T: PartialOrd<U> + Debug, U: Debug,

Assert that self is less than other.

Source

pub fn is_greater_than_or_equal_to<U>(self, other: U) -> BinaryAssertion<T, U>
where T: PartialOrd<U> + Debug, U: Debug,

Assert that self is greater than or equal to other.

Source

pub fn is_less_than_or_equal_to<U>(self, other: U) -> BinaryAssertion<T, U>
where T: PartialOrd<U> + Debug, U: Debug,

Assert that self is less than or equal to other.

Source

pub fn is_in(self, container: &[T]) -> BinaryAssertion<&[T], T>
where T: PartialEq,

Assert that self is contained by other.

Source

pub fn is_not_in(self, container: &[T]) -> BinaryAssertion<&[T], T>
where T: PartialEq,

Assert that self is not contained by other.

Source§

impl<T> Assert<&T>

Source

pub fn cloned(self) -> Assert<T>
where T: Clone,

Maps an Assert<&T> to Assert<T> by cloning the contained value.

Source

pub const fn copied(self) -> Assert<T>
where T: Copy,

Maps an Assert<&T> to Assert<T> by copying the contained value.

Source§

impl Assert<bool>

Source

pub const fn is_true(self) -> UnaryAssertion<bool>

Assert that self is true.

Source

pub const fn is_false(self) -> UnaryAssertion<bool>

Assert that self is false.

Source§

impl<T: Debug> Assert<Option<T>>

Source

pub fn is_some(self) -> UnaryAssertion<Option<T>>

Assert that self is Some.

Source

pub fn is_none(self) -> UnaryAssertion<Option<T>>

Assert that self is None.

Source

pub fn is_some_and<F, A>(self, f: F) -> UnaryAssertion<Option<T>>
where F: Fn(Assert<&T>) -> A, A: Assertion,

Assert that self is Some and the Some value matches a predicate.

Source

pub fn is_none_or<F, A>(self, f: F) -> UnaryAssertion<Option<T>>
where F: Fn(Assert<&T>) -> A, A: Assertion,

Assert that self is None or the Some value matches a predicate.

Source§

impl<T: Debug, E: Debug> Assert<Result<T, E>>

Source

pub fn is_ok(self) -> UnaryAssertion<Result<T, E>>

Assert that self is Ok.

Source

pub fn is_err(self) -> UnaryAssertion<Result<T, E>>

Assert that self is Err.

Source

pub fn is_ok_and<F, A>(self, f: F) -> impl Assertion
where F: Fn(Assert<&T>) -> A, A: Assertion,

Assert that self is Ok and the Ok value matches a predicate.

Source

pub fn is_err_and<F, A>(self, f: F) -> UnaryAssertion<Result<T, E>>
where F: Fn(Assert<&E>) -> A, A: Assertion,

Assert that self is Err and the Err value matches a predicate.

Source§

impl<'a, T> Assert<&'a [T]>

Source

pub fn is_sorted(self) -> UnaryAssertion<&'a [T]>
where T: PartialOrd,

Assert that self is sorted according to PartialOrd::partial_cmp.

Source

pub fn is_not_sorted(self) -> UnaryAssertion<&'a [T]>
where T: PartialOrd,

Assert that self is not sorted according to PartialOrd::partial_cmp.

Source

pub fn is_sorted_by<'b, F>(self, compare: F) -> UnaryAssertion<&'a [T]>
where F: FnMut(&'b T, &'b T) -> bool, 'a: 'b,

Assert that self is sorted according to the provided comparison function.

Source

pub fn is_not_sorted_by<'b, F>(self, compare: F) -> UnaryAssertion<&'a [T]>
where F: FnMut(&'b T, &'b T) -> bool, 'a: 'b,

Assert that self is not sorted according to the provided comparison function.

Source

pub fn is_sorted_by_key<'b, F, K>(self, f: F) -> UnaryAssertion<&'a [T]>
where F: FnMut(&'b T) -> K, K: PartialOrd, 'a: 'b,

Assert that self is sorted according to the provided key extraction function.

Source

pub fn is_not_sorted_by_key<'b, F, K>(self, f: F) -> UnaryAssertion<&'a [T]>
where F: FnMut(&'b T) -> K, K: PartialOrd, 'a: 'b,

Assert that self is not sorted according to the provided key extraction function.

Source

pub const fn is_empty(self) -> UnaryAssertion<&'a [T]>

Assert that self is empty.

Source

pub const fn is_not_empty(self) -> UnaryAssertion<&'a [T]>

Assert that self is not empty.

Source

pub const fn is_len(self, len: usize) -> BinaryAssertion<&'a [T], usize>

Assert that self has the given length.

Source

pub const fn is_not_len(self, len: usize) -> BinaryAssertion<&'a [T], usize>

Assert that self does not have the given length.

Source

pub fn contains(self, elem: T) -> BinaryAssertion<&'a [T], T>
where T: PartialEq,

Assert that self contains elem.

Source

pub fn does_not_contain(self, elem: T) -> BinaryAssertion<&'a [T], T>
where T: PartialEq,

Assert that self does not contain elem.

Trait Implementations§

Source§

impl<T: Clone> Clone for Assert<T>

Source§

fn clone(&self) -> Assert<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Copy> Copy for Assert<T>

Source§

impl<T: Debug> Debug for Assert<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Assert<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Assert<T>
where T: RefUnwindSafe,

§

impl<T> Send for Assert<T>
where T: Send,

§

impl<T> Sync for Assert<T>
where T: Sync,

§

impl<T> Unpin for Assert<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Assert<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Assert<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.