This is what I’d like to do:
pub trait MyTrait {
fn get_template_data(&self) -> &dyn serde::Serialize;
// Error: the trait `Serialize` cannot be made into an object
}
Alas, serde::Serialize
isn’t object-safe, so dyn
doesn’t work here.
MyTrait
must remain object-safe, so I can’t use generics. impl
would also have been OK but is not allowed in traits, either. Is there a way to do this?