#[message]Expand description
Derive actor message convenience methods on a Handle.
Applied to a message enum, this attribute generates an extension trait {Actor}Ext
and implements it for Handle<Actor>, giving each enum variant a corresponding async method.
§Variant Attributes
- (none) — variant sent with
Handle::cast(fire-and-forget); method returnsResult<(), ActorDead<()>>. #[call]— variant usesHandle::call; method returnsResult<(), ActorDead<()>>.#[call(ReturnType)]— variant usesHandle::call; method returnsResult<ReturnType, ActorDead<()>>.
For #[call] variants the macro appends a respond_to: oneshot::Sender<ReturnType>
field to the variant. The actor must send a value through it.
§Example
ⓘ
struct MyActor;
#[stagecraft::message(MyActor)]
pub enum MyActorMessage {
Log { text: String }, // cast: fire-and-forget
#[call(u64)]
Count, // call: returns u64
}
// The macro generates:
// pub trait MyActorExt {
// async fn log(&self, text: String) -> Result<(), ActorDead<()>>;
// async fn count(&self) -> Result<u64, ActorDead<()>>;
// }
// impl MyActorExt for Handle<MyActor> { ... }