Skip to main content

ContextProvider

Trait ContextProvider 

Source
pub trait ContextProvider<E: ProducerEffect>: Send + Sync {
    // Required method
    fn provide_context(
        &self,
        producer: &ProducerInstance,
        effect: &EffectPayload<E>,
    ) -> Vec<(FieldId, OwnedFieldValue)>;
}
Expand description

Typed, owner-supplied context provider for an OwnerProvided binding.

Issue #342 — some routes need consumer-side fields that aren’t in the producer’s effect body (the canonical case is session_id on the meerkat_mob_seam composition: the mob effect doesn’t carry it, but the consumer’s applied input requires it). Rather than smuggle that state through a serde_json::Value side channel, the runtime that owns the dispatcher supplies it through a typed context provider.

Exactly one method, no serde_json::Value in the signature. The returned fields are typed OwnedFieldValues keyed by FieldId — the same representation the route-binding table already uses for producer-field projections. The dispatcher can merge the provider’s fields with producer-projected fields when constructing the typed input for a ConsumerSurface.

Implementations are synchronous and infallible: context retrieval should be an in-process lookup against state the runtime already owns (pinned session id, realm id, bind-epoch, …). Anything that could fail belongs on the producer effect body or on the consumer surface.

Required Methods§

Source

fn provide_context( &self, producer: &ProducerInstance, effect: &EffectPayload<E>, ) -> Vec<(FieldId, OwnedFieldValue)>

Produce the owner-supplied typed context fields for a routed effect emitted by producer.

The returned vector’s FieldIds must match the route’s BindingSource::ContextField references declared in the composition schema (#342). Missing ids surface as DispatchRefusal::MissingProducerField at the dispatcher in the same way unfulfilled producer fields do — the dispatcher treats producer and owner-provided fields uniformly once projection starts.

Implementors§