Created
August 13, 2020 18:28
-
-
Save carrotflakes/8ad806cc21ce5e633f2c7622ea441ef5 to your computer and use it in GitHub Desktop.
Rust function that takes mut ref and returns FnMut
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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