Macro diverge::diverge
[−]
[src]
macro_rules! diverge { ($e:expr) => { ... }; }
Aborts the outer function if given Some
by returning its value, or continues the function
if given None
. This is particularly useful for understandable extension injection site
specification.
Example
fn reject_if_wrong_password(password: &str) -> Option<bool> { match password { "let_me_in" => None, _ => { // Hide the responsibility of recording the failure from `test_password()` record_failed_login_attempt(); Some(false) }, } } fn test_password(password: &str) -> bool { diverge!(reject_if_wrong_password(password)); true }