The problem comes from the log()
method depending on a generic parameter.
When a trait is implemented in order to achieve dynamic polymorphism, (you can call this trait an interface) each implementer must provide an implementation of the expected function with the exact same prototype.
However, using a generic can be seen as defining exactly the prototype only at the call site (with actual types chosen); such a prototype cannot have been determined beforehand by the implementers in order to prepare the virtual-tables.
If your approach strongly relies on dynamic polymorphism (OO), then you should probably also consider the event
parameter of log()
the same way: event: &dyn Keyed
.
Then, you would be able to return a Box<dyn EventPersister>
.
You will face the same problem about Serialize
since this trait (from serde
, I assume) is not object-safe for the same reason (generic parameters).
Maybe should you introduce a serialize()
method in Keyed
and rely internally on serde::Serialize
in the implementers?