[][src]Macro cursive::immut1

macro_rules! immut1 {
    ($f:expr ; else $else:expr) => { ... };
    ($f:expr) => { ... };
}

Macro to wrap a FnMut with 1 argument into a Fn.

This can wrap any FnMut with a single arguments (for example &mut Cursive).

See immut2! and immut3! to support a different number of arguments.

Note

If this function tries to call itself recursively (for example by triggering an event in Cursive), the second call will be a no-op. Enabling recursive calls would break the FnMut contract.

In addition, due to weird interaction between Higher-rank trait bounds and closures, you should use the result from the macro directly, and not assign it to a variable.

Examples

let mut i = 0;
// `Cursive::add_global_callback` takes a `Fn(&mut Cursive)`
siv.add_global_callback(
    'q',
    immut1!(move |s: &mut Cursive| {
        // But here we mutate the environment! Crazy!
        i += 1;
        if i == 5 {
            s.quit();
        }
    }),
);