I'm trying to declare a const closure so I can use throughout my code:
impl<T: Default + Copy + Eq> Profiler<T> {
pub const increase_by_one: dyn Fn(&T) = &|x| {
*x = *x + 1;
};
but I'm getting problems in the size not being known at compile time.
I also tried this:
impl<T: Default + Copy + Eq> Profiler<T> {
pub const increase_by_one: fn(&T) = &|x| {
*x = *x + 1;
};
But it says that the type of x
must be known.
Is there a way to define a closure inside a generic struct?