Skip to content

Instantly share code, notes, and snippets.

@gwy15 gwy15/v2ex_673374.rs
Last active May 19, 2020

Embed
What would you like to do?
fn close_test4() {
let string_postfix = "456";
let closure = move |mut s: String| {
s.push_str(string_postfix);
s
};
let mut vec_of_closures = Vec::new();
// vec_of_closures.push(closure);
push_closure_to_vec(closure, &mut vec_of_closures);
let extended_s = vec_of_closures[0]("123".into());
println!("{}", extended_s);
let extended_s = vec_of_closures[0]("abc".into());
println!("{}", extended_s);
}
fn push_closure_to_vec<T>(closure: T, v: &mut Vec<T>)
where
T: Fn(String) -> String,
{
v.push(closure);
}
fn main() {
close_test4();
}
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.