You are probably looking for DeserializeSeed
. You can implement this trait on MessageDescriptor
to guide the deserialization process in which types are expected.
Here is a rough version how it can look like: Rust Playground
As a sidenote: I would avoid using flatten
if not necessary, since it can have some unintended side effects. For the two cases you can replace it with transparent
.