Skip to main content

ContextInboundInterceptor

Struct ContextInboundInterceptor 

Source
pub struct ContextInboundInterceptor { /* private fields */ }
Expand description

Inbound interceptor that propagates dcontext automatically through actor message handlers.

This interceptor performs two complementary actions:

  1. on_receive — Normalizes context headers: if only wire bytes (ContextHeader) are present (remote hop), deserializes them into a ContextSnapshotHeader. Local snapshots are left as-is.

  2. wrap_handler — Wraps the handler future with dcontext::with_context, restoring the propagated context into the async task-local scope. This makes dcontext::get_context / dcontext::set_context work automatically inside the handler — no manual with_propagated_context() call needed.

§Error Handling

Controlled by ErrorPolicy:

  • LogAndContinue (default) — log and deliver the message without context.
  • Reject — reject the message.

§Usage

use dcontext_dactor::{ContextOutboundInterceptor, ContextInboundInterceptor};

// Register interceptors — context propagation is fully automatic
runtime.add_outbound_interceptor(Box::new(ContextOutboundInterceptor::default()));
runtime.add_inbound_interceptor(Box::new(ContextInboundInterceptor::default()));

// In the handler, dcontext is available without any boilerplate:
#[async_trait]
impl Handler<MyMessage> for MyActor {
    async fn handle(&mut self, msg: MyMessage, ctx: &mut ActorContext) -> () {
        let rid: RequestId = dcontext::get_context("request_id");
        // ... context is automatically restored by the interceptor
    }
}

Implementations§

Source§

impl ContextInboundInterceptor

Source

pub fn new(error_policy: ErrorPolicy) -> Self

Create with a specific error policy.

Trait Implementations§

Source§

impl Default for ContextInboundInterceptor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl InboundInterceptor for ContextInboundInterceptor

Source§

fn name(&self) -> &'static str

Human-readable name for this interceptor.
Source§

fn on_receive( &self, _ctx: &InboundContext<'_>, _runtime_headers: &RuntimeHeaders, headers: &mut Headers, _message: &dyn Any, ) -> Disposition

Called before the message is delivered to the handler. The message body is provided as &dyn Any for optional downcasting.
Source§

fn wrap_handler<'a>( &'a self, _ctx: &InboundContext<'_>, headers: &Headers, ) -> Option<HandlerWrapper<'a>>

Creates a wrapper for the handler dispatch future, enabling async context that persists through handler execution. Read more
Source§

fn on_complete( &self, _ctx: &InboundContext<'_>, _runtime_headers: &RuntimeHeaders, _headers: &Headers, _outcome: &Outcome<'_>, )

Called after the handler finishes. Called exactly once per delivered message. For ask, the Outcome::AskSuccess variant carries the type-erased reply.
Source§

fn on_expand_item( &self, ctx: &InboundContext<'_>, headers: &Headers, seq: u64, item: &(dyn Any + 'static), ) -> Disposition

Called for each item in a stream or feed. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more