Skip to main content

try_map

Function try_map 

Source
pub fn try_map<'a, Projection, Output, NewType, Args, Descr>(
    proj: Projection,
) -> Handler<'a, Output, Descr>
where Asyncify<Projection>: Injectable<Result<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 passes a value of a new type further.

Like map, the result of invoking proj is added to the container and passed further down the chain, but proj returns Result<NewType, E>:

  • Ok(v): v is inserted into the container and the continuation is called.
  • Err(e): the handler short-circuits and returns ControlFlow::Break with an error value built from e, without calling the continuation.

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.

See also: try_filter_map.