pub struct AnyMessage(/* private fields */);Expand description
A heap-allocated message that can be downcasted to a concrete message type.
It can be thought as a working version of Box<dyn Message>.
AnyMessage implements Message, thus it can be used in any context
where a message is expected, e.g. sending via Context’s methods.
AnyMessage doesn’t implement Request, so it’s useful only
for regular messages. However, requests are also messages and can
be converted to AnyMessage, but usage is limited in this case.
Implementations§
Source§impl AnyMessage
impl AnyMessage
Sourcepub fn new<M: Message>(message: M) -> Self
pub fn new<M: Message>(message: M) -> Self
Converts a message into AnyMessage.
Sourcepub fn as_ref(&self) -> AnyMessageRef<'_>
pub fn as_ref(&self) -> AnyMessageRef<'_>
Returns AnyMessageRef that borrows the message.
Sourcepub fn is<M: Message>(&self) -> bool
pub fn is<M: Message>(&self) -> bool
Checks if the message is of a specific type.
Note: it returns true if M is AnyMessage.
Sourcepub fn downcast_ref<M: Message>(&self) -> Option<&M>
pub fn downcast_ref<M: Message>(&self) -> Option<&M>
Tries to downcast the message to a reference to the concrete type.
Note: it returns Some(&self) if M is AnyMessage.
Sourcepub fn downcast_mut<M: Message>(&mut self) -> Option<&mut M>
pub fn downcast_mut<M: Message>(&mut self) -> Option<&mut M>
Tries to downcast the message to a mutable reference to the concrete type.
Note: it returns Some(&mut self) if M is AnyMessage.
Sourcepub fn downcast<M: Message>(self) -> Result<M, AnyMessage>
pub fn downcast<M: Message>(self) -> Result<M, AnyMessage>
Tries to downcast the message to a concrete type.