I was able to make this code work:
fn twice<T: Clone>(fst: impl Fn(T), snd: impl Fn(T)) -> impl Fn(T) {
move |t| {
fst(t.clone());
snd(t)
}
}
However, what I want is this (without boxing):
fn sub<T: Clone>(mut fst: impl Fn(T), snd: impl Fn(T)) {
fst = move |t: T| {
fst(t.clone());
snd(t)
};
}
Is there a way I can make the second piece of code work without boxing, using traits, type casting or any other method? Rust complains that the types do not match.