Trait stateright::actor::Actor

source ·
pub trait Actor: Sized {
    type Msg: Clone + Debug + Eq + Hash;
    type Timer: Clone + Debug + Eq + Hash;
    type State: Clone + Debug + PartialEq + Hash;

    // Required method
    fn on_start(&self, id: Id, o: &mut Out<Self>) -> Self::State;

    // Provided methods
    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>,
        _timer: &Self::Timer,
        o: &mut Out<Self>
    ) { ... }
    fn name(&self) -> String { ... }
}
Expand description

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

Required Associated Types§

source

type Msg: Clone + Debug + Eq + Hash

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

type Timer: Clone + Debug + Eq + Hash

The type for tagging timers.

Example
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
enum MyActorTimer { Event1, Event2 }
source

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 }

Required Methods§

source

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

Indicates the initial state and commands.

Provided Methods§

source

fn on_msg( &self, id: Id, state: &mut Cow<'_, 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.

source

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

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

source

fn name(&self) -> String

Implementations on Foreign Types§

source§

impl<A> Actor for Choice<A, Never>where A: Actor,

§

type Msg = <A as Actor>::Msg

§

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

§

type Timer = <A as Actor>::Timer

source§

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

source§

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

source§

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

source§

fn name(&self) -> String

source§

impl<Msg, Timer, A1, A2> Actor for Choice<A1, A2>where Msg: Clone + Debug + Eq + Hash, Timer: Clone + Debug + Eq + Hash + Serialize, A1: Actor<Msg = Msg, Timer = Timer>, A2: Actor<Msg = Msg, Timer = Timer>,

§

type Msg = Msg

§

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

§

type Timer = Timer

source§

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

source§

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

source§

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

source§

fn name(&self) -> String

source§

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

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

§

type Timer = ()

source§

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

source§

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

source§

fn name(&self) -> String

Implementors§

source§

impl<A: Actor> Actor for ActorWrapper<A>where A::Msg: Hash,

§

type Msg = MsgWrapper<<A as Actor>::Msg>

§

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

§

type Timer = TimerWrapper<<A as Actor>::Timer>

source§

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

§

type Msg = RegisterMsg<u64, char, InternalMsg>

§

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

§

type Timer = <ServerActor as Actor>::Timer

source§

impl<ServerActor, InternalMsg> Actor for WORegisterActor<ServerActor>where ServerActor: Actor<Msg = WORegisterMsg<u64, char, InternalMsg>>, InternalMsg: Clone + Debug + Eq + Hash,

§

type Msg = WORegisterMsg<u64, char, InternalMsg>

§

type State = WORegisterActorState<<ServerActor as Actor>::State, u64>

§

type Timer = <ServerActor as Actor>::Timer