Skip to main content

Actor

Trait Actor 

Source
pub trait Actor: Send + 'static {
    type Call: ActorMessage;
    type Reply: ActorMessage;
    type Cast: ActorMessage;

    // Required methods
    fn handle_call(
        &mut self,
        request: Self::Call,
        ctx: &mut ActorContext<'_, '_>,
    ) -> Self::Reply;
    fn handle_cast(
        &mut self,
        request: Self::Cast,
        ctx: &mut ActorContext<'_, '_>,
    );
}
Expand description

A gen_server-style actor running over a NativeHandler.

An actor owns private state and reacts to a Actor::Call (request/reply, answered with a Actor::Reply) or a Actor::Cast (fire-and-forget). The adapter drains the mailbox, decodes each call/cast envelope, dispatches to the methods below, routes replies back by ref, and parks when the mailbox drains — the author writes none of that.

Required Associated Types§

Source

type Call: ActorMessage

Request type delivered to Actor::handle_call.

Source

type Reply: ActorMessage

Reply type returned from Actor::handle_call.

Source

type Cast: ActorMessage

Message type delivered to Actor::handle_cast.

Required Methods§

Source

fn handle_call( &mut self, request: Self::Call, ctx: &mut ActorContext<'_, '_>, ) -> Self::Reply

Handle a request and return the reply (the adapter routes it back to the caller by ref).

Do NOT attempt a blocking SenderHandle::call from here — it deadlocks the worker thread (module docs). To ask another actor, ActorContext::cast it a message carrying ctx.self_pid() and handle the answer as a later cast.

Source

fn handle_cast(&mut self, request: Self::Cast, ctx: &mut ActorContext<'_, '_>)

Handle a fire-and-forget message. No reply is sent.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§