Skip to main content

Module pipeline

Module pipeline 

Source
Expand description

Monadic router pipeline for composable, error-propagating route registration.

RouterPipeline wraps Result<Router<()>> and provides a fluent builder API where every step is Result::and_then (>>=). A failed step short-circuits all subsequent steps. The error surfaces at .build().

§The Kleisli Model

Each mount::<C>(state) call creates a Kleisli arrow Router<()> -> Result<Router<()>> from the controller’s mount fn and threads it through the pipeline via and_then. The pipeline IS the Kleisli compositor — controllers are pure arrows, they don’t compose themselves.

§Algebraic Operations

MethodConceptDescription
map(f)Functor (fmap)Infallible Router -> Router transform
and_then(f)Monad bind (>>=)Fallible Router -> Result<Router>
mount::<C>(state)Kleisli bindThread router through a Controller arrow
mount_if::<C>(bool, state)Conditional bindMount only when condition is true
mount_guarded::<C>(state, g)Guarded bindMount only when guard g() succeeds
fold(steps)CatamorphismApply a dynamic list of fallible steps
layer_all(transforms)fold over transformsApply a list of Router -> Router fns
group(prefix, f)Scoped functorSub-pipeline with path prefix applied
route(info, handler)Route registrationStateless route via route info tuple
build()Interpreter / runConsume pipeline, surface Result<Router<()>>

§Example

let health_svc = Arc::new(HealthService::new());
let echo_svc   = Arc::new(EchoService::new());

let app = RouterPipeline::new()
    .mount::<HealthController>(health_svc)
    .mount_if::<EchoController>(config.enable_echo, echo_svc)
    .route(__root_route, root_handler)
    .map(|r| r.layer(TraceLayer::new_for_http()))
    .map(|r| r.layer(CorsLayer::permissive()))
    .build()?;

Structs§

RouterPipeline
Monadic router builder that propagates errors through the pipeline via Kleisli composition.

Type Aliases§

RouterTransform
A boxed, infallible router transformation.