Skip to content

Instantly share code, notes, and snippets.

@ficapy ficapy/closure.rs
Created Dec 2, 2019

Embed
What would you like to do?
fn apply<F>(mut f: F)
where
F: FnMut(),
{
f();
f();
}
fn main() {
let mut farewell = "goodbye".to_owned();
let mut diary = move || {
farewell.push_str("!!!");
println!("{}.", farewell);
};
apply(diary.clone());
apply(&mut diary);
apply(diary);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.