Skip to main content

RemoteActor

Derive Macro RemoteActor 

Source
#[derive(RemoteActor)]
{
    // Attributes available to this derive:
    #[message]
}
Expand description

Derive the RemoteActor trait for an actor.

Without any attribute, only the marker impl RemoteActor for Self {} is emitted.

With an optional #[message(M1, M2, ...)] attribute, an additional impl Handler<RemoteMessage> for Self is emitted which dispatches inbound messages by matching their message_id against <Mi as Decode>::ID and invoking the corresponding message handler <Self as Handler<Mi>>::handle. After handling the message, the response is encoded and sent back through an oneshot channel to the sender of the RemoteMessage.

For each Mi, the actor must implement Handler<Mi> trait and the result type of the trait must implement Encode trait.

§Example

use acktor_derive::RemoteActor;

#[derive(RemoteActor)]
#[message(Ping, Echo)]
pub struct MyActor;