Trait stateright::actor::Actor[][src]

pub trait Actor: Sized {
    type Msg: Clone + Debug + Eq + Hash;
    type State: Clone + Debug + PartialEq + Hash;
    fn on_start(&self, id: Id, o: &mut Out<Self>) -> Self::State;
fn on_msg(
        &self,
        id: Id,
        state: &mut Cow<'_, Self::State>,
        src: Id,
        msg: Self::Msg,
        o: &mut Out<Self>
    ); fn on_timeout(
        &self,
        _id: Id,
        _state: &mut Cow<'_, Self::State>,
        _o: &mut Out<Self>
    ) { ... } }

An actor initializes internal state optionally emitting outputs; then it waits for incoming events, responding by updating its internal state and optionally emitting outputs.

Associated Types

type Msg: Clone + Debug + Eq + Hash[src]

The type of messages sent and received by the actor.

Example

use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[derive(Serialize, Deserialize)]
enum MyActorMsg { Msg1(u64), Msg2(char) }

type State: Clone + Debug + PartialEq + Hash[src]

The type of state maintained by the actor.

Example

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
struct MyActorState { sequencer: u64 }
Loading content...

Required methods

fn on_start(&self, id: Id, o: &mut Out<Self>) -> Self::State[src]

Indicates the initial state and commands.

fn on_msg(
    &self,
    id: Id,
    state: &mut Cow<'_, Self::State>,
    src: Id,
    msg: Self::Msg,
    o: &mut Out<Self>
)
[src]

Indicates the next state and commands when a message is received. See Out::send.

Loading content...

Provided methods

fn on_timeout(
    &self,
    _id: Id,
    _state: &mut Cow<'_, Self::State>,
    _o: &mut Out<Self>
)
[src]

Indicates the next state and commands when a timeout is encountered. See Out::set_timer.

Loading content...

Implementations on Foreign Types

impl<A> Actor for Choice<A, Never> where
    A: Actor
[src]

type Msg = A::Msg

type State = Choice<A::State, Never>

fn on_start(&self, id: Id, o: &mut Out<Self>) -> Self::State[src]

fn on_msg(
    &self,
    id: Id,
    state: &mut Cow<'_, Self::State>,
    src: Id,
    msg: Self::Msg,
    o: &mut Out<Self>
)
[src]

fn on_timeout(
    &self,
    id: Id,
    state: &mut Cow<'_, Self::State>,
    o: &mut Out<Self>
)
[src]

impl<Msg, A1, A2> Actor for Choice<A1, A2> where
    Msg: Clone + Debug + Eq + Hash,
    A1: Actor<Msg = Msg>,
    A2: Actor<Msg = Msg>, 
[src]

type Msg = Msg

type State = Choice<A1::State, A2::State>

fn on_start(&self, id: Id, o: &mut Out<Self>) -> Self::State[src]

fn on_msg(
    &self,
    id: Id,
    state: &mut Cow<'_, Self::State>,
    src: Id,
    msg: Self::Msg,
    o: &mut Out<Self>
)
[src]

fn on_timeout(
    &self,
    id: Id,
    state: &mut Cow<'_, Self::State>,
    o: &mut Out<Self>
)
[src]

impl<Msg> Actor for Vec<(Id, Msg)> where
    Msg: Clone + Debug + Eq + Hash
[src]

Sends a series of messages in sequence to the associated actor Ids waiting for a message delivery between each. This is useful for testing actor systems.

type Msg = Msg

type State = usize

fn on_start(&self, _id: Id, o: &mut Out<Self>) -> Self::State[src]

fn on_msg(
    &self,
    _id: Id,
    state: &mut Cow<'_, Self::State>,
    _src: Id,
    _msg: Self::Msg,
    o: &mut Out<Self>
)
[src]

Loading content...

Implementors

impl<A: Actor> Actor for ActorWrapper<A> where
    A::Msg: Hash
[src]

type Msg = MsgWrapper<A::Msg>

type State = StateWrapper<A::Msg, A::State>

fn on_start(&self, id: Id, o: &mut Out<Self>) -> Self::State[src]

fn on_msg(
    &self,
    id: Id,
    state: &mut Cow<'_, Self::State>,
    src: Id,
    msg: Self::Msg,
    o: &mut Out<Self>
)
[src]

fn on_timeout(
    &self,
    _id: Id,
    state: &mut Cow<'_, Self::State>,
    o: &mut Out<Self>
)
[src]

impl<ServerActor, InternalMsg> Actor for RegisterActor<ServerActor> where
    ServerActor: Actor<Msg = RegisterMsg<u64, char, InternalMsg>>,
    InternalMsg: Clone + Debug + Eq + Hash
[src]

type Msg = RegisterMsg<u64, char, InternalMsg>

type State = RegisterActorState<ServerActor::State, u64>

fn on_start(&self, id: Id, o: &mut Out<Self>) -> Self::State[src]

fn on_msg(
    &self,
    id: Id,
    state: &mut Cow<'_, Self::State>,
    src: Id,
    msg: Self::Msg,
    o: &mut Out<Self>
)
[src]

Loading content...