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>
impl<I, F: Fn(I) -> bool, M: Display> Assertion<I, F, M>
Sourcepub const fn new(message: M, function: F) -> Self
pub const fn new(message: M, function: F) -> Self
Create a new Assertion with the provided message
that calls the provided function
.
Sourcepub fn assert_with<Msg: Display>(&self, input: I, msg: Msg)
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.
Sourcepub fn debug_assert(&self, input: I)
pub fn debug_assert(&self, input: I)
Assert the function with the given input
in dev.
Sourcepub fn debug_assert_with<Msg: Display>(&self, input: I, msg: Msg)
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>
impl<I, F, M> RefUnwindSafe for Assertion<I, F, M>
impl<I, F, M> Send for Assertion<I, F, M>
impl<I, F, M> Sync for Assertion<I, F, M>
impl<I, F, M> Unpin for Assertion<I, F, M>
impl<I, F, M> UnwindSafe for Assertion<I, F, M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more