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 }
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]
&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
.
Provided methods
fn on_timeout(
&self,
_id: Id,
_state: &mut Cow<'_, Self::State>,
_o: &mut Out<Self>
)
[src]
&self,
_id: Id,
_state: &mut Cow<'_, Self::State>,
_o: &mut Out<Self>
)
Indicates the next state and commands when a timeout is encountered. See Out::set_timer
.
Implementations on Foreign Types
impl<A> Actor for Choice<A, Never> where
A: Actor,
[src]
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]
&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>
)
[src]
&self,
id: Id,
state: &mut Cow<'_, Self::State>,
o: &mut Out<Self>
)
impl<Msg, A1, A2> Actor for Choice<A1, A2> where
Msg: Clone + Debug + Eq + Hash,
A1: Actor<Msg = Msg>,
A2: Actor<Msg = Msg>,
[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]
&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>
)
[src]
&self,
id: Id,
state: &mut Cow<'_, Self::State>,
o: &mut Out<Self>
)
impl<Msg> Actor for Vec<(Id, Msg)> where
Msg: Clone + Debug + Eq + Hash,
[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 Id
s waiting for a message
delivery between each. This is useful for testing actor systems.
Implementors
impl<A: Actor> Actor for ActorWrapper<A> where
A::Msg: Hash,
[src]
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]
&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>
)
[src]
&self,
_id: Id,
state: &mut Cow<'_, Self::State>,
o: &mut Out<Self>
)