Skip to main content

ContextService

Type Alias ContextService 

Source
pub type ContextService = BoxCloneSyncService<Context, Context, YetiError>;
Expand description

The middleware-pipeline service type. Each registered service consumes a Context and returns a (possibly mutated) Context, or fails with YetiError.

This is the Tower-native replacement for the legacy RequestMiddleware trait. Build one with tower::service_fn:

โ“˜
use yeti_types::plugins::{ContextService, service_fn};
use tower::util::BoxCloneSyncService;

let svc: ContextService = BoxCloneSyncService::new(service_fn(|mut ctx: Context| async move {
    ctx.set_access(/* ... */);
    Ok::<_, YetiError>(ctx)
}));

Uses BoxCloneSyncService (rather than plain BoxCloneService) so the type is Send + Sync โ€” the router stores its frozen snapshot inside Arc<[ContextService]> and the surrounding AutoRouter is shared across threads.

Aliased Typeยง

pub struct ContextService(/* private fields */);