Struct Assertion

Source
pub struct Assertion<I, F: Fn(I) -> bool = fn(I) -> bool, M: Display = &'static str> { /* private fields */ }
Expand description

An assert function with a message for runtime assertions.

§Example

let asserter = Assertion::new("lhs is not equal to rhs.", |(lhs, rhs)| lhs == rhs);
asserter.assert((4, 4));
// Will panic here.
asserter.assert((4, 5));
 
asserter.debug_assert((4, 4));
// Will panic here in dev.
asserter.debug_assert((4, 5));

Implementations§

Source§

impl<I, F: Fn(I) -> bool, M: Display> Assertion<I, F, M>

Source

pub const fn new(message: M, function: F) -> Self

Create a new Assertion with the provided message that calls the provided function.

Source

pub fn assert(&self, input: I)

Assert the function with the given input.

Source

pub fn assert_with<Msg: Display>(&self, input: I, msg: Msg)

Assert the function with the given input, displaying the given msg if the assertion fails.

Source

pub fn debug_assert(&self, input: I)

Assert the function with the given input in dev.

Source

pub fn debug_assert_with<Msg: Display>(&self, input: I, msg: Msg)

Assert the function with the given input in dev, displaying the given msg if the assertion fails.

Auto Trait Implementations§

§

impl<I, F, M> Freeze for Assertion<I, F, M>
where F: Freeze, M: Freeze,

§

impl<I, F, M> RefUnwindSafe for Assertion<I, F, M>

§

impl<I, F, M> Send for Assertion<I, F, M>
where F: Send, M: Send, I: Send,

§

impl<I, F, M> Sync for Assertion<I, F, M>
where F: Sync, M: Sync, I: Sync,

§

impl<I, F, M> Unpin for Assertion<I, F, M>
where F: Unpin, M: Unpin, I: Unpin,

§

impl<I, F, M> UnwindSafe for Assertion<I, F, M>
where F: UnwindSafe, M: UnwindSafe, I: 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> 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, 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.