Skip to main content

Actor

Derive Macro Actor 

Source
#[derive(Actor)]
Expand description

Derive macro for automatically implementing the Actor trait.

This macro generates a default implementation of the Actor trait where:

  • Args type is set to Self
  • Error type is set to std::convert::Infallible
  • on_start method returns the args as the actor instance

§Examples

§Struct Actor

use rsactor::Actor;

#[derive(Actor)]
struct MyActor {
    name: String,
}

§Enum Actor

use rsactor::Actor;

#[derive(Actor)]
enum StateActor {
    Idle,
    Processing(String),
    Completed(i32),
}

This generates an implementation equivalent to:

impl rsactor::Actor for MyActor {
    type Args = Self;
    type Error = std::convert::Infallible;

    async fn on_start(
        args: Self::Args,
        _actor_ref: &rsactor::ActorRef<Self>,
    ) -> std::result::Result<Self, Self::Error> {
        Ok(args)
    }
}

§Limitations

  • Only works on structs and enums (not unions)
  • Generates a very basic implementation - for complex initialization logic, implement the Actor trait manually