Skip to main content

ChildPosition

Trait ChildPosition 

Source
pub trait ChildPosition<Children, Child: Behavior>: ChildPosition { }
Expand description

Static proof that Child occupies Position in a closed child sum.

This trait provides structural evidence only. It does not construct a choice, perform creation, or select a child through runtime inspection. A role cannot claim a position occupied by a different child:

ⓘ
use behavior::{
    Actions, Behavior, BehaviorActed, Births, ChildChoice, ChildHead,
    ChildRole, MailAddr, Never, NoBirths, User,
};
struct First;
struct Second;
struct Parent;
macro_rules! inert {
    ($actor:ty) => {
        impl behavior::Protocol for $actor {
            type Addr = MailAddr;
            type Msg = Never;
        }
        impl Behavior for $actor {
            type Protocol = Self;
            type Event = User<MailAddr, Never>;
            type Sends = Vec<Never>;
            type Ph = Never;
            type Error = Never;
            type Birth = NoBirths;
            fn transition(&mut self, _: behavior::ActiveTurn, event: Self::Event) -> BehaviorActed<Self> {
                match event.message {}
            }
        }
    };
}
inert!(First);
inert!(Second);
impl behavior::Protocol for Parent {
    type Addr = MailAddr;
    type Msg = Never;
}
impl Behavior for Parent {
    type Protocol = Self;
    type Event = User<MailAddr, Never>;
    type Sends = Vec<Never>;
    type Ph = Never;
    type Error = Never;
    type Birth = Births<ChildChoice<Second, ChildChoice<First, Never>>>;
    fn transition(&mut self, _: behavior::ActiveTurn, event: Self::Event) -> BehaviorActed<Self> {
        match event.message {}
    }
}
struct ForgedFirst;
impl ChildRole<Parent> for ForgedFirst {
    type Child = First;
    type Position = ChildHead;
}

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<Head, Tail, Position, Child> ChildPosition<ChildChoice<Head, Tail>, Child> for ChildTail<Position>
where Child: Behavior, Position: ChildPosition<Tail, Child>,

Source§

impl<Head: Behavior, Tail> ChildPosition<ChildChoice<Head, Tail>, Head> for ChildHead