#[derive(Actor)]
{
// Attributes available to this derive:
#[actor]
}
Expand description
Derives the Actor trait for a struct. By default, generates an implementation
with no params (type Params = () and async fn new(_params: ()) -> Result<Self, anyhow::Error>).
This requires that the Actor implements Default.
If the #[actor(passthrough)] attribute is specified, generates an implementation
with where the parameter type is Self
(type Params = Self and async fn new(instance: Self) -> Result<Self, anyhow::Error>).
§Examples
Default behavior:
#[derive(Actor, Default)]
struct MyActor(u64);Generates:
ⓘ
#[async_trait]
impl Actor for MyActor {
type Params = ();
async fn new(_params: ()) -> Result<Self, anyhow::Error> {
Ok(Default::default())
}
}Passthrough behavior:
#[derive(Actor, Default)]
#[actor(passthrough)]
struct MyActor(u64);Generates:
ⓘ
#[async_trait]
impl Actor for MyActor {
type Params = Self;
async fn new(instance: Self) -> Result<Self, anyhow::Error> {
Ok(instance)
}
}