pub struct ContextInboundInterceptor { /* private fields */ }Expand description
Inbound interceptor that propagates dcontext automatically through actor message handlers.
This interceptor performs two complementary actions:
-
on_receive— Normalizes context headers: if only wire bytes (ContextHeader) are present (remote hop), deserializes them into aContextSnapshotHeader. Local snapshots are left as-is. -
wrap_handler— Wraps the handler future withdcontext::with_context, restoring the propagated context into the async task-local scope. This makesdcontext::get_context/dcontext::set_contextwork automatically inside the handler — no manualwith_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
impl ContextInboundInterceptor
Sourcepub fn new(error_policy: ErrorPolicy) -> Self
pub fn new(error_policy: ErrorPolicy) -> Self
Create with a specific error policy.
Trait Implementations§
Source§impl Default for ContextInboundInterceptor
impl Default for ContextInboundInterceptor
Source§impl InboundInterceptor for ContextInboundInterceptor
impl InboundInterceptor for ContextInboundInterceptor
Source§fn on_receive(
&self,
_ctx: &InboundContext<'_>,
_runtime_headers: &RuntimeHeaders,
headers: &mut Headers,
_message: &dyn Any,
) -> Disposition
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>>
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<'_>,
)
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
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§
impl Freeze for ContextInboundInterceptor
impl RefUnwindSafe for ContextInboundInterceptor
impl Send for ContextInboundInterceptor
impl Sync for ContextInboundInterceptor
impl Unpin for ContextInboundInterceptor
impl UnsafeUnpin for ContextInboundInterceptor
impl UnwindSafe for ContextInboundInterceptor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more