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
| Method | Concept | Description |
|---|---|---|
map(f) | Functor (fmap) | Infallible Router -> Router transform |
and_then(f) | Monad bind (>>=) | Fallible Router -> Result<Router> |
mount::<C>(state) | Kleisli bind | Thread router through a Controller arrow |
mount_if::<C>(bool, state) | Conditional bind | Mount only when condition is true |
mount_guarded::<C>(state, g) | Guarded bind | Mount only when guard g() succeeds |
fold(steps) | Catamorphism | Apply a dynamic list of fallible steps |
layer_all(transforms) | fold over transforms | Apply a list of Router -> Router fns |
group(prefix, f) | Scoped functor | Sub-pipeline with path prefix applied |
route(info, handler) | Route registration | Stateless route via route info tuple |
build() | Interpreter / run | Consume 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§
- Router
Pipeline - Monadic router builder that propagates errors through the pipeline via Kleisli composition.
Type Aliases§
- Router
Transform - A boxed, infallible router transformation.