Function xpct::try_map

source ·
pub fn try_map<'a, In, Out>(
    func: impl FnOnce(In) -> Result<Out> + 'a
) -> Matcher<'a, In, Out>where
    In: 'a,
    Out: 'a,
Expand description

Fallibly map the input value by applying a function to it.

This does the same thing as Assertion::try_map.

This matcher always succeeds as long as func returns Ok, even when negated. Therefore negating it has no effect.

Examples

use xpct::{expect, equal, try_map};

expect!(vec![0x43, 0x75, 0x6e, 0x6f])
    .to(try_map(|bytes| Ok(String::from_utf8(bytes)?)))
    .to(equal("Cuno"));