Skip to main content

BehaviorLayer

Trait BehaviorLayer 

Source
pub trait BehaviorLayer<B: Behavior>
where <Self::Output as Behavior>::Protocol: Protocol<Addr = BehaviorAddr<B>>,
{ type Output: Behavior; // Required method fn layer(&self, inner: B) -> Self::Output; }
Expand description

Static construction from one concrete behavior to another.

This is Bombay’s generic consumer contract for Tower-like behavior composition. Output remains a fully concrete Behavior, so its public protocol, complete event sum, named send product, birth algebra, initialization fold, phase, error, and next-behavior decision all remain available through ordinary associated types. A layer value performs no send, creation, initialization, transition, or runtime lookup; it only owns the information needed to construct its output.

The output remains in the input behavior’s address namespace. It may preserve or deliberately adapt the public protocol, event, sends, births, phase, and error only as documented by the concrete output behavior. This trait does not assert that an arbitrary closure is topology-transparent; that semantic law belongs to the concrete transformation and its tests.

Closures implement this contract directly, allowing existing concrete wrapper constructors to compose without a parallel catalogue of marker or configuration-only *Layer types:

struct Inner;
impl behavior::Protocol for Inner { type Addr = behavior::MailAddr; type Msg = (); }
impl behavior::Behavior for Inner {
    type Protocol = Self;
    type Event = behavior::User<behavior::MailAddr, ()>;
    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()) }
}

fn apply<B, L>(behavior: B, layer: L) -> L::Output
where
    B: behavior::Behavior,
    L: behavior::BehaviorLayer<B>,
{
    behavior::BehaviorLayer::layer(&layer, behavior)
}

let _: Inner = apply(Inner, core::convert::identity::<Inner>);

Required Associated Types§

Source

type Output: Behavior

Fully concrete behavior constructed by this layer.

Required Methods§

Source

fn layer(&self, inner: B) -> Self::Output

Construct one concrete composition from inner.

The layer is borrowed so a topology owner can apply the same stateless or configuration-bearing construction law to every child it owns.

Implementors§

Source§

impl<B, F, Output> BehaviorLayer<B> for F
where B: Behavior, F: Fn(B) -> Output, Output: Behavior, Output::Protocol: Protocol<Addr = BehaviorAddr<B>>,

Source§

type Output = Output