[−][src]Struct riker::actor::Props
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.
Methods
impl Props
[src]
pub fn new<A>(
creator: Box<dyn Fn() -> A + Send>
) -> Arc<Mutex<Box<dyn ActorProducer<Actor = A>>>> where
A: Actor + Send + 'static,
[src]
creator: Box<dyn Fn() -> A + Send>
) -> Arc<Mutex<Box<dyn ActorProducer<Actor = A>>>> where
A: Actor + Send + 'static,
Creates an ActorProducer
with no factory method parameters.
Examples
struct User; impl User { fn actor() -> BoxActor<String> { Box::new(User) } } // main let model: DefaultModel<String> = DefaultModel::new(); let system = ActorSystem::new(&model).unwrap(); let props = Props::new(Box::new(User::actor)); // start the actor and get an `ActorRef` let actor = system.actor_of(props, "user").unwrap();
pub fn new_args<A, Args>(
creator: Box<dyn Fn(Args) -> A + Send>,
args: Args
) -> Arc<Mutex<Box<dyn ActorProducer<Actor = A>>>> where
A: Actor + Send + 'static,
Args: ActorArgs + 'static,
[src]
creator: Box<dyn Fn(Args) -> A + Send>,
args: Args
) -> Arc<Mutex<Box<dyn ActorProducer<Actor = A>>>> where
A: Actor + Send + 'static,
Args: ActorArgs + 'static,
Creates an ActorProducer
with one or more factory method parameters.
Examples
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) } } // main 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) } } // main 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())); // start the actor and get an `ActorRef` let actor = system.actor_of(props, "bank_account").unwrap();
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,