Expand description
A procedural macro that brings C-style goto to Rust.
Apply goto to any function and use label!(name) and goto!(name) inside its body.
The macro rewrites the function at compile time into a state-machine loop — no unsafe,
no runtime overhead beyond the loop itself.
Two optional modes are available:
#[goto(debug)]— printsjumping to <label>to stdout on everygoto!().#[goto(strict)]— turns forward-goto side-effect hazards into compile errors.
Modes may be combined: #[goto(debug, strict)].
§Quick start
use gotobykkrwhofrags::goto;
#[goto]
fn count_up(limit: i32) -> i32 {
let mut n = 0;
label!(top);
n += 1;
if n < limit { goto!(top); }
n
}
assert_eq!(count_up(5), 5);Attribute Macros§
- goto
- Enables
label!(name)andgoto!(name)inside a function.