pub trait Behavior {
type Protocol: Protocol;
type Event: UserEvent<Addr = BehaviorAddr<Self>, Message = BehaviorMessage<Self>>;
type Sends: SendEffects + SendsFor<Self::Event>;
type Ph;
type Error;
type Birth: BirthMode;
// Required method
fn transition(
&mut self,
_turn: ActiveTurn,
event: Self::Event,
) -> BehaviorActed<Self>;
// Provided methods
fn init(&mut self, _turn: InitializationTurn) -> BehaviorActed<Self>
where Self: Sized { ... }
fn layer<L>(self, layer: L) -> L::Output
where Self: Sized,
L: BehaviorLayer<Self> { ... }
}Expand description
A composed pure behavior. Event is the complete accepted input algebra;
the separately declared Protocol is stable public destination identity,
and every successful transition returns the declared Actions value.
The public protocol must exactly match the address and user-message lane:
struct Wrong;
impl behavior::Protocol for Wrong {
type Addr = behavior::MailAddr;
type Msg = String;
}
struct Counter;
impl behavior::Protocol for Counter {
type Addr = behavior::MailAddr;
type Msg = u8;
}
impl behavior::Behavior for Counter {
type Protocol = Wrong;
type Event = behavior::User<behavior::MailAddr, u8>;
type Sends = Vec<behavior::Never>;
type Ph = behavior::Never;
type Error = behavior::Never;
type Birth = behavior::NoBirths;
fn transition(&mut self, _: behavior::ActiveTurn, _: Self::Event) -> behavior::BehaviorActed<Self> {
Ok(behavior::Actions::cont())
}
}Required Associated Types§
Sourcetype Protocol: Protocol
type Protocol: Protocol
Stable public communication identity owned by this actor template.
Behavior wrappers must preserve this type unless their documented purpose is to adapt the public message protocol. The equality bound prevents a behavior from consuming a different address or user-message signature than the protocol established for its actor identity.
type Event: UserEvent<Addr = BehaviorAddr<Self>, Message = BehaviorMessage<Self>>
type Sends: SendEffects + SendsFor<Self::Event>
type Ph
type Error
type Birth: BirthMode
Required Methods§
Sourcefn transition(
&mut self,
_turn: ActiveTurn,
event: Self::Event,
) -> BehaviorActed<Self>
fn transition( &mut self, _turn: ActiveTurn, event: Self::Event, ) -> BehaviorActed<Self>
Fold exactly one event into explicit actions and the next behavior.
§Errors
Returns the behavior’s declared controlled transition failure.
Provided Methods§
Sourcefn init(&mut self, _turn: InitializationTurn) -> BehaviorActed<Self>where
Self: Sized,
fn init(&mut self, _turn: InitializationTurn) -> BehaviorActed<Self>where
Self: Sized,
Produce initialization actions before the first event is accepted.
§Errors
Returns the behavior’s declared controlled initialization failure.
Sourcefn layer<L>(self, layer: L) -> L::Outputwhere
Self: Sized,
L: BehaviorLayer<Self>,
fn layer<L>(self, layer: L) -> L::Outputwhere
Self: Sized,
L: BehaviorLayer<Self>,
Apply one statically dispatched construction layer.
The returned concrete behavior is inferred from layer; no trait
object or erased behavior is introduced. Construction performs no
actor effect and does not run either initialization or a transition.