pub trait LocalActor: 'static {
type Message: Send + 'static;
type State: 'static;
type Initialize: 'static;
// Required methods
async fn initialize(
&self,
handle: &ActorHandle<Self::Message>,
tags: &Tags,
initialize: Self::Initialize,
) -> Result<Self::State, ActorError>;
async fn handle(
&self,
handle: &ActorHandle<Self::Message>,
message: Self::Message,
state: &mut Self::State,
) -> Result<(), ActorError>;
// Provided methods
fn tags(&self, tags: Tags) -> Result<Tags, ActorError> { ... }
async fn shutdown(&self, _state: Self::State) -> Result<(), ActorError> { ... }
fn spawner(
tags: Tags,
actor: Self,
) -> Result<LocalActorSpawner<Self>, ActorError>
where Self: Sized + 'static { ... }
fn spawn_with(
spawner: impl LocalTaskSpawner,
tags: Tags,
actor: Self,
initialize: Self::Initialize,
) -> Result<LocalActorInstance<Self>, ActorError>
where Self: Sized + 'static { ... }
}Expand description
A LocalActor will not moved between threads.
This is sometimes necessary when interfacing with external code.
This trait allows to implement such behaviour with same public interface as a normal [Actor] (ActorHandle).
For new code that dont have this requirement is usually better to use [Actor] as it allows to use multithreading.
Required Associated Types§
Required Methods§
async fn initialize( &self, handle: &ActorHandle<Self::Message>, tags: &Tags, initialize: Self::Initialize, ) -> Result<Self::State, ActorError>
async fn handle( &self, handle: &ActorHandle<Self::Message>, message: Self::Message, state: &mut Self::State, ) -> Result<(), ActorError>
Provided Methods§
Sourceasync fn shutdown(&self, _state: Self::State) -> Result<(), ActorError>
async fn shutdown(&self, _state: Self::State) -> Result<(), ActorError>
Shutdown the actor. This is not cancelable. After this call no more message will be received. Will not be executed if actor panics.
fn spawner(
tags: Tags,
actor: Self,
) -> Result<LocalActorSpawner<Self>, ActorError>where
Self: Sized + 'static,
Sourcefn spawn_with(
spawner: impl LocalTaskSpawner,
tags: Tags,
actor: Self,
initialize: Self::Initialize,
) -> Result<LocalActorInstance<Self>, ActorError>where
Self: Sized + 'static,
fn spawn_with(
spawner: impl LocalTaskSpawner,
tags: Tags,
actor: Self,
initialize: Self::Initialize,
) -> Result<LocalActorInstance<Self>, ActorError>where
Self: Sized + 'static,
Spawn actor using a task spawner.
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.