pub trait AsyncActor {
type Message: Send + 'static;
type Error: Display;
const DEFAULT_CAPACITY_NORMAL: usize = 5;
const DEFAULT_CAPACITY_HIGH: usize = 5;
// Required method
async fn handle(
&mut self,
context: &BareContext<Self::Message>,
message: Self::Message,
) -> Result<(), Self::Error>;
// Provided methods
fn name() -> &'static str { ... }
fn priority(_message: &Self::Message) -> Priority { ... }
async fn started(
&mut self,
_context: &BareContext<Self::Message>,
) -> Result<(), Self::Error> { ... }
async fn stopped(
&mut self,
_context: &BareContext<Self::Message>,
) -> Result<(), Self::Error> { ... }
fn addr() -> Addr<Self::Message> { ... }
fn addr_with_capacity(capacity: impl Into<Capacity>) -> Addr<Self::Message> { ... }
}Expand description
The actor trait - async variant.
Provided Associated Constants§
Sourceconst DEFAULT_CAPACITY_NORMAL: usize = 5
const DEFAULT_CAPACITY_NORMAL: usize = 5
Default capacity of actor’s normal-priority inbox unless overridden by .with_capacity().
Sourceconst DEFAULT_CAPACITY_HIGH: usize = 5
const DEFAULT_CAPACITY_HIGH: usize = 5
Default capacity of actor’s high-priority inbox unless overridden by .with_capacity().
Required Associated Types§
Required Methods§
Sourceasync fn handle(
&mut self,
context: &BareContext<Self::Message>,
message: Self::Message,
) -> Result<(), Self::Error>
async fn handle( &mut self, context: &BareContext<Self::Message>, message: Self::Message, ) -> Result<(), Self::Error>
The primary function of this trait, allowing an actor to handle incoming messages of
a certain type. Note that the actor system still calls this serially for each message even
for async actors; not even control messages (currently the request to stop the actor) are
processed while the future returned by handle() is still pending.
Delegate work to an async task if you want to process messages and control events
concurrently. This is recommended especially if the handle() can take extended/arbitrary
time to fully resolve and you want the actor to stay responsive.
Provided Methods§
Sourcefn name() -> &'static str
fn name() -> &'static str
The name of the Actor. Used only for logging/debugging.
Default implementation uses type_name().
Sourcefn priority(_message: &Self::Message) -> Priority
fn priority(_message: &Self::Message) -> Priority
Determine priority of a message before it is sent to this actor.
Default implementation returns Priority::Normal.
Sourceasync fn started(
&mut self,
_context: &BareContext<Self::Message>,
) -> Result<(), Self::Error>
async fn started( &mut self, _context: &BareContext<Self::Message>, ) -> Result<(), Self::Error>
An optional callback when the Actor has been started.
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.