let_else!() { /* proc-macro */ }Expand description
A procedural macro that extends let-else with explicit else bindings.
§Syntax
let_else!(PAT = EXPR else as REST { /* else block */ });
let_else!(PAT = EXPR else match { /* match arms */ });REST can be a pattern (including |-separated patterns) or a single
identifier. When match is used, provide full match arms for the else
branch.
§Examples
Simple else binding:
fn foo(value: Result<i32, String>) {
let_else!(Ok(value) = value else as Err(err) {
eprintln!("Error: {}", err);
return;
});
}Complete else match:
fn bar(value: Result<i32, String>) {
let_else!(Ok(value) = value else match {
Err(err) => {
eprintln!("Error: {}", err);
return;
}
});
}§Notes
- The expression is evaluated once and reused in the else branch.
- The macro generates an unreachable arm for the success pattern.