Trait Protocol

Source
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§

Source

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.

Source

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).

Source

fn accepts(id: &TypeId) -> bool
where Self: Sized,

Whether the Protocol accepts a message.

The type-id given here is the TypeId of the message, and should return true if this message is accepted.

Implementors§