Skip to main content

TestPanicResult

Enum TestPanicResult 

Source
pub enum TestPanicResult<R> {
    Cool(R),
    Panic(Box<dyn Any + Send>),
}
Expand description

Result of test_panic function.

Variants§

§

Cool(R)

No panic result. Contains callback function result.

§

Panic(Box<dyn Any + Send>)

Panic result. Contains panic payload.

Implementations§

Source§

impl<R> TestPanicResult<R>

Source

pub fn is_cool(&self) -> bool

Returns true if self is Cool.

Source

pub fn is_panic(&self) -> bool

Returns true if self is Panic.

Source

pub fn cool(self) -> Option<R>

Converts self into success result if any.

Source

pub fn panic(self) -> Option<Box<dyn Any + Send>>

Converts self into panic payload if any.

Source

pub fn value(&self) -> &R

Returns result value.

§Panics

Panics if self is Panic.

Source

pub fn payload(&self) -> &Box<dyn Any + Send>

Returns panic payload.

§Panics

Panics if self is Cool.

Source

pub fn message(&self) -> String

Returns panic message.

§Panics

Panics if self is Cool or panic payload is not &str or String.

Source

pub fn get_message(&self) -> Option<String>

Returns panic message if exists.

Source

pub fn eq_almost(&self, other: &Self) -> bool
where R: PartialEq,

Tests self and other values to be almost equal.

This method ignores error message, only if other has no message. This is useful for toggling verification based on whether the message is known or not.

Source

pub fn eq_nearly(&self, other: &Self) -> bool
where R: PartialEq,

Tests self and other values to be nearly equal.

This method ignores error message. This is useful when comparing two functions with similar behavior, but where only the error messages differ.

Trait Implementations§

Source§

impl<R: Debug> Debug for TestPanicResult<R>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<R> PartialEq for TestPanicResult<R>
where R: PartialEq,

Compare result and error message.

§Notes

Errors are compared by Self::get_message. So, precise values of error payloads are not used.

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<R> Eq for TestPanicResult<R>
where R: Eq,

Auto Trait Implementations§

§

impl<R> Freeze for TestPanicResult<R>
where R: Freeze,

§

impl<R> !RefUnwindSafe for TestPanicResult<R>

§

impl<R> Send for TestPanicResult<R>
where R: Send,

§

impl<R> !Sync for TestPanicResult<R>

§

impl<R> Unpin for TestPanicResult<R>
where R: Unpin,

§

impl<R> !UnwindSafe for TestPanicResult<R>

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.