pub trait Actor:
Sized
+ Send
+ Debug
+ 'static {
type Params: Send + 'static;
// Required method
fn new<'async_trait>(
params: Self::Params,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>
where Self: 'async_trait;
// Provided methods
fn init<'life0, 'life1, 'async_trait>(
&'life0 mut self,
_this: &'life1 Instance<Self>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn spawn<'life0, 'async_trait>(
cap: &'life0 (impl CanSpawn + 'async_trait),
params: Self::Params,
) -> Pin<Box<dyn Future<Output = Result<ActorHandle<Self>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait { ... }
fn spawn_detached<'async_trait>(
params: Self::Params,
) -> Pin<Box<dyn Future<Output = Result<ActorHandle<Self>, Error>> + Send + 'async_trait>>
where Self: 'async_trait { ... }
fn spawn_server_task<F>(future: F) -> JoinHandle<<F as Future>::Output>
where F: Future + Send + 'static,
<F as Future>::Output: Send + 'static { ... }
fn handle_supervision_event<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
_this: &'life1 Instance<Self>,
_event: &'life2 ActorSupervisionEvent,
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait { ... }
fn handle_undeliverable_message<'life0, 'life1, 'async_trait>(
&'life0 mut self,
cx: &'life1 Instance<Self>,
__arg2: Undeliverable<MessageEnvelope>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
}
Expand description
An Actor is an independent, asynchronous thread of execution. Each
actor instance has a mailbox, whose messages are delivered through
the method [Actor::handle
].
Actors communicate with each other by way of message passing. Actors are assumed to be deterministic: that is, the state of an actor is determined by the set (and order) of messages it receives.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn init<'life0, 'life1, 'async_trait>(
&'life0 mut self,
_this: &'life1 Instance<Self>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn init<'life0, 'life1, 'async_trait>(
&'life0 mut self,
_this: &'life1 Instance<Self>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Initialize the actor, after the runtime has been fully initialized. Init thus provides a mechanism by which an actor can reliably and always receive some initial event that can be used to kick off further (potentially delayed) processing.
Sourcefn spawn<'life0, 'async_trait>(
cap: &'life0 (impl CanSpawn + 'async_trait),
params: Self::Params,
) -> Pin<Box<dyn Future<Output = Result<ActorHandle<Self>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn spawn<'life0, 'async_trait>(
cap: &'life0 (impl CanSpawn + 'async_trait),
params: Self::Params,
) -> Pin<Box<dyn Future<Output = Result<ActorHandle<Self>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Spawn a child actor, given a spawning capability (usually given by Instance
).
The spawned actor will be supervised by the parent (spawning) actor.
Sourcefn spawn_detached<'async_trait>(
params: Self::Params,
) -> Pin<Box<dyn Future<Output = Result<ActorHandle<Self>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
fn spawn_detached<'async_trait>(
params: Self::Params,
) -> Pin<Box<dyn Future<Output = Result<ActorHandle<Self>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
Spawns this actor in a detached state, handling its messages in a background task. The returned handle is used to control the actor’s lifecycle and to interact with it.
Actors spawned through spawn_detached
are not attached to a supervision
hierarchy, and not managed by a Proc
.
Sourcefn spawn_server_task<F>(future: F) -> JoinHandle<<F as Future>::Output>
fn spawn_server_task<F>(future: F) -> JoinHandle<<F as Future>::Output>
This method is used by the runtime to spawn the actor server. It can be used by actors that require customized runtime setups (e.g., dedicated actor threads), or want to use a custom tokio runtime.
Sourcefn handle_supervision_event<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
_this: &'life1 Instance<Self>,
_event: &'life2 ActorSupervisionEvent,
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn handle_supervision_event<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
_this: &'life1 Instance<Self>,
_event: &'life2 ActorSupervisionEvent,
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Handle actor supervision event. Return `Ok(true)`` if the event is handled here.
Sourcefn handle_undeliverable_message<'life0, 'life1, 'async_trait>(
&'life0 mut self,
cx: &'life1 Instance<Self>,
__arg2: Undeliverable<MessageEnvelope>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn handle_undeliverable_message<'life0, 'life1, 'async_trait>(
&'life0 mut self,
cx: &'life1 Instance<Self>,
__arg2: Undeliverable<MessageEnvelope>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Default undeliverable message handling behavior.
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.
Implementations on Foreign Types§
Source§impl Actor for ()
An actor that does nothing. It is used to represent “client only” actors,
returned by Proc::instance
.
impl Actor for ()
An actor that does nothing. It is used to represent “client only” actors,
returned by Proc::instance
.