Skip to main content

try_filter_map

Function try_filter_map 

Source
pub fn try_filter_map<'a, Projection, Output, NewType, Args, Descr>(
    proj: Projection,
) -> Handler<'a, Output, Descr>
where Asyncify<Projection>: Injectable<Result<Option<NewType>, Output::Error>, Args> + MaybeSend + MaybeSync + 'a, Output: Fallible + 'a, Output::Error: MaybeSend, Descr: HandlerDescription, NewType: Send + Sync + 'static,
Expand description

Constructs a fallible handler that optionally passes a value of a new type further.

Like filter_map, proj may add a value to the container, but it returns Result<Option<NewType>, E>:

  • Ok(Some(v)): v is inserted into the container and the continuation is called.
  • Ok(None): the handler returns ControlFlow::Continue (it tries the next branch), just like filter_map returning None.
  • Err(e): the handler short-circuits and returns ControlFlow::Break with an error value built from e.

The handler Output must be fallible (i.e. implement Fallible); in practice this means it is a Result<T, E>, and E is the error type that proj returns on failure.