Expand description
This crate provides a sound and safe way to jump from a goto forward in the control-flow to a label.
Rust has no goto mechanism with which it is possible to arbitrarily jump through the control-flow.
This crates provides a procedural macro that allows to write gotos that can jump forward in the control-flow to a specified label.
The jump is safe in terms of the borrow-checker, but several
restrictions apply. See rewrite_forward_goto
for more information.
use forward_goto::rewrite_forward_goto;
#[rewrite_forward_goto]
fn decode_msg(luck: impl Fn() -> bool, is_alan_turing: bool) {
if is_alan_turing {
forward_goto!('turing_complete);
}
println!("You'll need a lot of luck for this");
if luck() {
println!("Seems you were lucky");
forward_label!('turing_complete);
println!("Message decoded!");
} else {
println!("No luck today...");
}
}
Attribute Macrosยง
- rewrite_
forward_ goto - This macro will rewrite the annotated function so that the control-flow
will go from a goto
forward_goto!('label)
directly to a corresponding labelforward_label!('label)
.