pub trait ResolveChildOccurrence<Occurrence>: Behavior + ResolveChildOccurrence<Occurrence> {
type Child: Behavior;
type Position: ChildPosition<<Self::Birth as BirthMode>::Child, Self::Child>;
}Expand description
Resolve an effect’s nominal or structural occurrence against the concrete behavior currently being interpreted.
This is a sealed, type-level derived construction. It performs no lookup,
allocates no actor, and introduces no second identity: the resolved child’s
Behavior::Protocol remains canonical identity, while Position is only
navigation evidence into the emitter’s direct birth algebra.
A nominal role follows BehaviorBase through a wrapper only when the
wrapper preserves the exact protocol and the role’s declared child at its
exact structural position. A wrapper may append births after that position,
but it cannot replace, reorder, or insert births before it. Raw
ChildHead and ChildTail positions instead resolve directly against
the running emitter’s own birth algebra.
A wrapper that replaces its base role’s child cannot silently reuse that role:
struct ActorProtocol;
impl behavior::Protocol for ActorProtocol {
type Addr = behavior::MailAddr;
type Msg = behavior::Never;
}
macro_rules! inert {
($actor:ident, $birth:ty) => {
struct $actor;
impl behavior::Behavior for $actor {
type Protocol = ActorProtocol;
type Event = behavior::Never;
type Sends = behavior::NoSends;
type Ph = behavior::Never;
type Error = behavior::Never;
type Birth = $birth;
fn transition(
&mut self,
_: behavior::ActiveTurn,
event: behavior::Never,
) -> behavior::BehaviorActed<Self> {
match event {}
}
}
};
}
inert!(Child, behavior::NoBirths);
inert!(Proxy, behavior::NoBirths);
inert!(Parent, behavior::Births<Child>);
inert!(ChangedTopology, behavior::Births<Proxy>);
impl behavior::BehaviorBase for Parent {
type Base = Self;
fn base(&self) -> &Self { self }
}
impl behavior::BehaviorBase for ChangedTopology {
type Base = Parent;
fn base(&self) -> &Parent { unreachable!() }
}
struct WorkerRole;
impl behavior::ChildRole<Parent> for WorkerRole {
type Child = Child;
type Position = behavior::ChildHead;
}
impl behavior::ChildOccurrence<Parent> for WorkerRole {
type Resolution = behavior::DeclaredChildOccurrence;
}
fn require<T: behavior::ResolveChildOccurrence<WorkerRole>>() {}
require::<ChangedTopology>();