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

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>);
fn on_msg(
        &self,
        id: Id,
        state: &Self::State,
        src: Id,
        msg: Self::Msg,
        o: &mut Out<Self>
    ); fn on_timeout(&self, _id: Id, _state: &Self::State, _o: &mut Out<Self>) { ... }
fn on_start_out(&self, id: Id) -> Out<Self> { ... }
fn on_msg_out(
        &self,
        id: Id,
        state: &Self::State,
        src: Id,
        msg: Self::Msg
    ) -> Out<Self> { ... }
fn on_timeout_out(&self, id: Id, state: &Self::State) -> 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

The type of messages sent and received by the actor.

Example

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

type State: Clone + Debug + PartialEq + Hash

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>)

Indicates the initial state and commands.

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

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: &Self::State, _o: &mut Out<Self>)

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

fn on_start_out(&self, id: Id) -> Out<Self>

Returns the initial state and commands.

fn on_msg_out(
    &self,
    id: Id,
    state: &Self::State,
    src: Id,
    msg: Self::Msg
) -> Out<Self>

Returns the next state and commands when a message is received.

fn on_timeout_out(&self, id: Id, state: &Self::State) -> Out<Self>

Returns the next state and commands when a timeout is encountered.

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>

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

type Msg = RegisterMsg<TestRequestId, TestValue, InternalMsg>

type State = RegisterActorState<ServerActor::State>

Loading content...