Provides instances of ActorProducer
for use when creating Actors (actor_of
).
Actors are not created directly. Instead you provide an ActorProducer
that allows the ActorSystem
to start an actor when actor_of
is used,
or when an actor fails and a supervisor requests an actor to be restarted.
ActorProducer
can hold values required by the actor's factory method
parameters.
Creates an ActorProducer
with no factory method parameters.
struct User;
impl User {
fn actor() -> BoxActor<String> {
Box::new(User)
}
}
let model: DefaultModel<String> = DefaultModel::new();
let system = ActorSystem::new(&model).unwrap();
let props = Props::new(Box::new(User::actor));
let actor = system.actor_of(props, "user").unwrap();
Creates an ActorProducer
with one or more factory method parameters.
An actor requiring a single parameter.
struct User {
name: String,
}
impl User {
fn actor(name: String) -> BoxActor<String> {
let actor = User {
name
};
Box::new(actor)
}
}
let model: DefaultModel<String> = DefaultModel::new();
let system = ActorSystem::new(&model).unwrap();
let props = Props::new_args(Box::new(User::actor), "Naomi Nagata".into());
let actor = system.actor_of(props, "user").unwrap();
An actor requiring multiple parameters.
struct BankAccount {
name: String,
number: String,
}
impl BankAccount {
fn actor((name, number): (String, String)) -> BoxActor<String> {
let actor = BankAccount {
name,
number
};
Box::new(actor)
}
}
let model: DefaultModel<String> = DefaultModel::new();
let system = ActorSystem::new(&model).unwrap();
let props = Props::new_args(Box::new(BankAccount::actor),
("James Holden".into(), "12345678".into()));
let actor = system.actor_of(props, "bank_account").unwrap();
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)