Trait ProptestResultExt
pub trait ProptestResultExt<T, E>: Sealed
Extension trait for Result<T, E> to provide additional functionality
specifically for prop test cases.
Required Methods
fn prop_assume_ok(self) -> Result<T, TestCaseError> where E: Debug,Converts a
Result<T, E>into aResult<T, TestCaseError>, where theErrcase is transformed into aTestCaseError::Reject.This is intended to be used like the
prop_assume!macro, but for fallible computations. If the result isErr, the test input is rejected and a new input will be generated.Example
use proptest::prelude::*; fn test_conversion(a: i32) -> Result<(), TestCaseError> { // Reject the case if `a` cannot be converted to u8 (e.g., negative values) let _unsigned: u8 = a.try_into().prop_assume_ok()?; // ...rest of test... Ok(()) } proptest! { #[test] fn test_that_only_works_with_positive_integers(a in -10i32..10i32) { test_conversion(a)?; } }
Implementors
impl<T, E> ProptestResultExt<T, E> for Result<T, E>