I would like to be able to create different implementations of the Callback trait and pass it into the Clt so a call back can for example just log or just capture msg into a memory map, etc. Here is more to complete this example
If you don't want to parameterize your struct with a generic type, you'll need to either pick a specific implementing type or type erase implementing types.
You can erase implementing types with dyn Callback + '_. Here's one possible way, wherein the implementing type must also be 'static:
which is to say, it introduces a generic type parameter to the function. So the more direct translation for Ctl is indeed to add a generic type parameter to the struct.
Syntactically hiding the fact that a struct is generic, not being able to fully name the type with its concrete parameters, etc. would be a lot more problematic for structs than it is for fns.
but will probably give you grief within your current design âŠī¸
Thanks really, great suggestion but I am specifically trying to avoid dynamic dispatch in my case because the callback inside Clt struct is in the hot path.