pub trait ActorContext<A>:
Sized
+ Send
+ 'staticwhere
A: Actor<Context = Self>,{
Show 19 methods
// Required methods
fn new(label: String) -> Self;
fn index(&self) -> usize;
fn label(&self) -> &str;
fn address(&self) -> Address<A>;
fn take_mailbox(&mut self) -> Option<Mailbox<A>>;
fn state(&self) -> ActorState;
fn set_state(&mut self, state: ActorState);
fn supervisor(&self) -> Option<&Recipient<SupervisionEvent<A>>>;
fn set_supervisor(
&mut self,
supervisor: Option<Recipient<SupervisionEvent<A>>>,
);
fn processing(
&mut self,
actor: &mut A,
mailbox: Mailbox<A>,
) -> impl Future<Output = Result<(), A::Error>> + Send;
// Provided methods
fn set_error(&mut self, error: A::Error) { ... }
fn drain_mailbox(&mut self) { ... }
fn stop(&mut self) { ... }
fn stop_with_error(&mut self, error: A::Error) { ... }
fn terminate(&mut self) { ... }
fn terminate_with_error(&mut self, error: A::Error) { ... }
fn notify_supervisor(
&mut self,
event: SupervisionEvent<A>,
) -> impl Future<Output = ()> + Send { ... }
fn try_notify_supervisor(&mut self, event: SupervisionEvent<A>) { ... }
fn run(
self,
actor: A,
span: Span,
) -> Result<(Address<A>, JoinHandle<()>), A::Error> { ... }
}Expand description
Describes the execution context of an actor.
Required Methods§
Sourcefn take_mailbox(&mut self) -> Option<Mailbox<A>>
fn take_mailbox(&mut self) -> Option<Mailbox<A>>
Returns the mailbox of the actor.
Sourcefn state(&self) -> ActorState
fn state(&self) -> ActorState
Returns the state of the actor.
Sourcefn set_state(&mut self, state: ActorState)
fn set_state(&mut self, state: ActorState)
Sets the state of the actor.
Sourcefn supervisor(&self) -> Option<&Recipient<SupervisionEvent<A>>>
fn supervisor(&self) -> Option<&Recipient<SupervisionEvent<A>>>
Returns the address of the supervisor.
Sourcefn set_supervisor(&mut self, supervisor: Option<Recipient<SupervisionEvent<A>>>)
fn set_supervisor(&mut self, supervisor: Option<Recipient<SupervisionEvent<A>>>)
Sets a supervisor.
Sourcefn processing(
&mut self,
actor: &mut A,
mailbox: Mailbox<A>,
) -> impl Future<Output = Result<(), A::Error>> + Send
fn processing( &mut self, actor: &mut A, mailbox: Mailbox<A>, ) -> impl Future<Output = Result<(), A::Error>> + Send
Runs the main processing loop of the actor.
This method is called after post_start and drives the actor until
it stops. It is responsible for receiving messages from the mailbox and dispatching them
to the actor.
Provided Methods§
Sourcefn drain_mailbox(&mut self)
fn drain_mailbox(&mut self)
Drains the mailbox of the actor.
The default implementation does nothing. Users who needs this functionality should implement it in their own context.
Sourcefn stop_with_error(&mut self, error: A::Error)
fn stop_with_error(&mut self, error: A::Error)
Stops the actor and save the error for reporting.
This method will switch the actor to the Stopping state.
Sourcefn terminate(&mut self)
fn terminate(&mut self)
Terminates the actor.
This method will switch the actor to the Stopped state.
Sourcefn terminate_with_error(&mut self, error: A::Error)
fn terminate_with_error(&mut self, error: A::Error)
Terminates the actor and save the error for reporting.
This method will switch the actor to the Stopped state.
Sourcefn notify_supervisor(
&mut self,
event: SupervisionEvent<A>,
) -> impl Future<Output = ()> + Send
fn notify_supervisor( &mut self, event: SupervisionEvent<A>, ) -> impl Future<Output = ()> + Send
Notifies the supervisor for an event.
This method will wait until there is capacity in the mailbox of the supervisor.
Sourcefn try_notify_supervisor(&mut self, event: SupervisionEvent<A>)
fn try_notify_supervisor(&mut self, event: SupervisionEvent<A>)
Notifies the supervisor for an event.
This method will return immediately if there is no capacity in the mailbox of the supervisor.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.