Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
macro_rules! siaf {
(|$($parm:ident),* $(,)*| $body:expr) => {{
/* ensure no captures */ let closure: fn($($parm: _),*)->_ = |$($parm),*| $body;
(closure)($($parm),*)
}}
}
fn compute_g(a: i32, b: i32, c: i32) -> i32 {
let d = siaf!(|a, b| a + c);
let (e, f) = siaf!(|d| (d - 1, d + 1));
let g = siaf!(|c, e, f| c + e + f );
g
}
fn main() {
println!("{}", compute_g(1, 2, 3));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment