Skip to content

Instantly share code, notes, and snippets.

@carrotflakes
Created August 13, 2020 18:28
Show Gist options
  • Save carrotflakes/8ad806cc21ce5e633f2c7622ea441ef5 to your computer and use it in GitHub Desktop.
Save carrotflakes/8ad806cc21ce5e633f2c7622ea441ef5 to your computer and use it in GitHub Desktop.
Rust function that takes mut ref and returns FnMut
fn f<'a>(i: &'a mut i32) -> impl FnMut() -> i32 + 'a {
move|| {*i = *i + 1; *i}
}
fn main() {
let mut i = 0;
{
let mut ff = f(&mut i);
dbg!(ff());
dbg!(ff());
}
dbg!(i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment