pub trait Protocol: Send + 'static {
// Required methods
fn boxed(self) -> BoxedMessage;
fn try_unbox(boxed: BoxedMessage) -> Result<Self, BoxedMessage>
where Self: Sized;
fn accepts(id: &TypeId) -> bool
where Self: Sized;
}
Expand description
In order for an actor to receive any messages, it must first define a Protocol. This protocol defines exactly which Messages the actor can receive, and how to convert these messages into the Protocol that is received by the Inbox.
This is normally derived using the [protocol] macro, but may be implemented manually.
Required Methods§
Sourcefn boxed(self) -> BoxedMessage
fn boxed(self) -> BoxedMessage
Convert the Protocol into a BoxedMessage.
This should be implemented by matching on the message type creating a BoxedMessage from that.
Sourcefn try_unbox(boxed: BoxedMessage) -> Result<Self, BoxedMessage>where
Self: Sized,
fn try_unbox(boxed: BoxedMessage) -> Result<Self, BoxedMessage>where
Self: Sized,
Attempt to create the Protocol from a BoxedMessage.
This should return Ok(Self)
, if it is downcast-able to an accepted message.
Otherwise this should return Err(BoxedMessage)
.