Hi folks !
I have a problem / question with generics. I don't even know if what i'm trying to do is doable....
I have a vector of structs that contain a closure :
pub struct Handling<'a, E>{
pub handler: Box<dyn FnMut(&mut Arg) -> Result<(), E> + 'a>,
}
pub type Handlers<'a, E> = Vec<Handling<'a,E>>;
The thing is, in my code, I do this :
let handlers : Handlers = vec![
Handling {
handler : Box::from(|my_arg| { cast_function::<TypeA>(my_arg); ...}
},
Handling {
handler : Box::from(|my_arg| { cast_function::<TypeB>(my_arg); ...}
},
Handling {
handler : Box::from(|my_arg| { cast_function::<TypeC>(my_arg); ...}
},
]
I would LOVE to refactor this, in order to inject TypeA / TypeB / TypeC instead of my_arg into my closure parameter !
But is it possible ??? It would require to mix different generics in the same Vector, and I really don't know how to tackle the problem.
Note: I oversimplified the code in order to showcase my problem, I know my example doesn't compile, but my code do !