I'd like to create a struct that can hold on to a bunch of closures for me to later use them. The closures should also have the Clone
trait on them too.
What's the syntax for declaring that?
My attempt which doesn't compile:
pub struct Equations {
eqns:Vec<impl Fn(f32) -> f32 + Clone>,
}
And another attempt, I can't quite get the required syntax here (or how to look it up).
trait AnonFunction: Fn(f32) -> f32 + Clone {}
pub struct Equations {
eqns:Vec<dyn AnonFunction>,
}
Edit: Not sure why this was voted to be closed, I was linked to this question: How to represent an opaque type in a struct field which requires an understanding of async, macros, potentially the genawaiter crate just to understand what is being asked. And is a much longer question.
I think the question herein is simpler as it is only talking specifically about anonymous closures which suits the Q&A style format. I did go to the effort of making a simpler example, not just copying the code verbatim from my main project.