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
Required Associated Types§
sourcetype Msg: Clone + Debug + Eq + Hash
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) }
Required Methods§
Provided Methods§
sourcefn on_msg(
&self,
id: Id,
state: &mut Cow<'_, Self::State>,
src: Id,
msg: Self::Msg,
o: &mut Out<Self>
)
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
.
sourcefn on_timeout(
&self,
id: Id,
state: &mut Cow<'_, Self::State>,
_timer: &Self::Timer,
o: &mut Out<Self>
)
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
.
fn name(&self) -> String
Implementations on Foreign Types§
source§impl<Msg> Actor for Vec<(Id, Msg)>where
Msg: Clone + Debug + Eq + Hash,
impl<Msg> Actor for Vec<(Id, Msg)>where Msg: Clone + Debug + Eq + Hash,
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.