pub trait BehaviorLayer<B: Behavior>{
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>);