Type Alias DynMessage

Source
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 */);

Trait Implementations§

Source§

impl<T: 'static + Send + Sync> Repr<T> for DynMessage

We can turn anything into a DynMessage.

Source§

fn from(v: T) -> Self

Convert a raw type to the common representation.
Source§

fn try_into(self) -> Result<T, Self>

Try to convert the representation back into one of the raw message types.
Source§

fn can_into(&self) -> bool

Check whether the representation can be turned into this raw type, without consuming.