Skip to content

Instantly share code, notes, and snippets.

@ficapy
Created December 2, 2019 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ficapy/0518381448d707116ee626bf8a5a14d7 to your computer and use it in GitHub Desktop.
Save ficapy/0518381448d707116ee626bf8a5a14d7 to your computer and use it in GitHub Desktop.
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