Skip to main content

EstablishChild

Trait EstablishChild 

Source
pub trait EstablishChild<Occurrence, C>{
    // Required method
    fn establish_child(
        &mut self,
        creation: RoutedCreation<BehaviorAddr<C>, C>,
    ) -> impl Future<Output = ItemSettlement<RoutedCreation<BehaviorAddr<C>, C>, ChildCreationOutcome<C, Occurrence>, CreationRejection, Never>> + Send;
}
Expand description

Runtime ownership port for establishing one concrete child behavior.

The result vocabulary belongs to the creation request, never the runtime. Accepting ownership consumes the child definition and returns its one authoritative created-or-rejected result. Refusal before ownership transfer returns the complete request. Child creation has no prerequisite, while interpreter corruption uses the shared crate::InterpreterFault sum.

A runtime cannot substitute a private receipt or rejection type:

ⓘ
#[derive(Clone, Copy, Eq, PartialEq)]
struct RuntimeAddr;
impl behavior::Address for RuntimeAddr { type Nonce = u8; }
#[derive(Clone)]
struct Endpoint;
struct Installed<B: behavior::Behavior>(Endpoint, std::sync::mpsc::Sender<B::Event>);
impl<B: behavior::Behavior> Clone for Installed<B> {
    fn clone(&self) -> Self { Self(self.0.clone(), self.1.clone()) }
}
impl behavior::EndpointAddress for RuntimeAddr {
    type Established<P> = Endpoint where P: behavior::Protocol<Addr = Self>;
    type Installed<B> = Installed<B>
        where B: behavior::Behavior<Protocol: behavior::Protocol<Addr = Self>>;
    fn recipient<B>(installed: &Self::Installed<B>) -> Endpoint
    where B: behavior::Behavior<Protocol: behavior::Protocol<Addr = Self>> {
        installed.0.clone()
    }
}
struct Child;
impl behavior::Protocol for Child {
    type Addr = RuntimeAddr;
    type Msg = behavior::Never;
}
impl behavior::Behavior for Child {
    type Protocol = Self;
    type Event = behavior::User<RuntimeAddr, behavior::Never>;
    type Sends = behavior::NoSends;
    type Ph = behavior::Never;
    type Error = behavior::Never;
    type Birth = behavior::NoBirths;
    fn transition(
        &mut self,
        _: behavior::ActiveTurn,
        event: Self::Event,
    ) -> behavior::BehaviorActed<Self> {
        match event.message {}
    }
}
struct Runtime;

impl behavior::EstablishChild<behavior::ChildHead, Child> for Runtime {
    fn establish_child(
        &mut self,
        creation: behavior::RoutedCreation<behavior::BehaviorAddr<Child>, Child>,
    ) -> impl core::future::Future<Output = behavior::ItemSettlement<
        behavior::RoutedCreation<behavior::BehaviorAddr<Child>, Child>,
        (),
        &'static str,
        behavior::Never,
    >> + Send {
        async move { behavior::ItemSettlement::Rejected { item: creation, reason: "no" } }
    }
}

Required Methods§

Source

fn establish_child( &mut self, creation: RoutedCreation<BehaviorAddr<C>, C>, ) -> impl Future<Output = ItemSettlement<RoutedCreation<BehaviorAddr<C>, C>, ChildCreationOutcome<C, Occurrence>, CreationRejection, Never>> + Send

Establish exactly the supplied child or return its complete settlement.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§