pub type DynMessage = Box<dyn Any + Send + Sync + 'static>;
Expand description
We can use a dynamic boxed message to pass messages, and represent all messages in a protocol as individual structs. However if we want to send them over a network connection we will need to serialise to some wire format, and at that point we have to use tagging, so we can recognise what type to deserialise into.
It helps then to use something like an enum to represent the data, but the way protocols work is to use the sent and received types in their generic signatures, where enums would not work.
For this reason the channels have a generic parameter for the representation of the messages, which can be an outer
enum that handles all supported protocols, paired with From
and TryInto
traits for each possible message we want
to send during the sessions.
However for in-memory use cases DynMessage
still works fine.
Aliased Type§
pub struct DynMessage(/* private fields */);