[][src]Struct riker::actor::Props

pub struct 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]

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]

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

impl Send for Props

impl Sync for Props

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]