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

pub struct Props;

Provides instances of ActorProducer for use when creating Actors (actor_of_props).

Actors are not created directly. Instead you provide an ActorProducer that allows the ActorSystem to start an actor when actor_of_props 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.

Implementations

impl Props[src]

pub fn new_from<A, F>(creator: F) -> Arc<Mutex<impl ActorProducer<Actor = A>>> where
    A: Actor + Send + 'static,
    F: Fn() -> A + Send + 'static, 
[src]

Creates an ActorProducer with no factory method parameters.

Examples


struct User;

impl User {
    fn actor() -> Self {
        User
    }
}

// main
let sys = ActorSystem::new().unwrap();

let props = Props::new_from(User::actor);

// start the actor and get an `ActorRef`
let actor = sys.actor_of_props("user", props).unwrap();

pub fn new_from_args<A, Args, F>(
    creator: F,
    args: Args
) -> Arc<Mutex<impl ActorProducer<Actor = A>>> where
    A: Actor + Send + 'static,
    Args: ActorArgs,
    F: Fn(Args) -> A + Send + '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) -> Self {
        User {
            name
        }
    }
}

// main
let sys = ActorSystem::new().unwrap();

let props = Props::new_from_args(User::actor, "Naomi Nagata".into());

let actor = sys.actor_of_props("user", props).unwrap();

An actor requiring multiple parameters.


struct BankAccount {
    name: String,
    number: String,
}

impl BankAccount {
    fn actor((name, number): (String, String)) -> Self {
        BankAccount {
            name,
            number
        }
    }
}

// main
let sys = ActorSystem::new().unwrap();

let props = Props::new_from_args(BankAccount::actor,
                            ("James Holden".into(), "12345678".into()));

// start the actor and get an `ActorRef`
let actor = sys.actor_of_props("bank_account", props).unwrap();

pub fn new<A>() -> Arc<Mutex<impl ActorProducer<Actor = A>>> where
    A: ActorFactory
[src]

Creates an ActorProducer from default constructible type with no factory method parameters.

Examples


#[derive(Default)]
struct User;

// main
let sys = ActorSystem::new().unwrap();

let props = Props::new::<User>();

// start the actor and get an `ActorRef`
let actor = sys.actor_of_props("user", props).unwrap();

Creates an ActorProducer from a type which implements ActorFactory with no factory method parameters.

Examples


struct User;

impl ActorFactory for User {
    fn create() -> Self {
        User
    }
}

// main
let sys = ActorSystem::new().unwrap();

let props = Props::new::<User>();

// start the actor and get an `ActorRef`
let actor = sys.actor_of_props("user", props).unwrap();

pub fn new_args<A, Args>(
    args: Args
) -> Arc<Mutex<impl ActorProducer<Actor = A>>> where
    A: ActorFactoryArgs<Args>,
    Args: ActorArgs
[src]

Creates an ActorProducer from a type which implements ActorFactoryArgs with one or more factory method parameters.

Examples

An actor requiring a single parameter.


struct User {
    name: String,
}

impl ActorFactoryArgs<String> for User {
    fn create_args(name: String) -> Self {
        User {
            name
        }
    }
}

// main
let sys = ActorSystem::new().unwrap();

let props = Props::new_args::<User, _>("Naomi Nagata".into());

let actor = sys.actor_of_props("user", props).unwrap();

An actor requiring multiple parameters.


struct BankAccount {
    name: String,
    number: String,
}

impl ActorFactoryArgs<(String, String)> for BankAccount {
    fn create_args((name, number): (String, String)) -> Self {
        BankAccount {
            name,
            number
        }
    }
}

// main
let sys = ActorSystem::new().unwrap();

let props = Props::new_from_args(BankAccount::create_args,
                            ("James Holden".into(), "12345678".into()));

// start the actor and get an `ActorRef`
let actor = sys.actor_of_props("bank_account", props).unwrap();

Auto Trait Implementations

impl RefUnwindSafe for Props

impl Send for Props

impl Sync for Props

impl Unpin for Props

impl UnwindSafe for Props

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

impl<T> SendSyncUnwindSafe for T where
    T: Send + Sync + UnwindSafe + ?Sized
[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,