Module tsukuyomi::modifier [−][src]
Components for supporting modifiers.
The main trait for supporting the middlewares is Modifier
.
This trait is used to insert some processes before and/or after calling the handler recognized by the
router.
NOTE:
The purpose of abstraction by using Modifier
is to provide a basic extension for HTTP
usage.
If you want to do more complex management (such as connection-level logging, load balancing),
consider wrapping the instance of App
and implements Service
for adding the features from
the outside.
Examples
use std::sync::atomic::{AtomicUsize, Ordering}; use tsukuyomi::{App, Input, Handler}; use tsukuyomi::modifier::{Modifier, BeforeHandle, AfterHandle}; #[derive(Default)] struct RequestCounter(AtomicUsize); impl Modifier for RequestCounter { fn before_handle(&self, _: &mut Input) -> BeforeHandle { self.0.fetch_add(1, Ordering::SeqCst); BeforeHandle::ok() } } let app = App::builder() .mount("/", |m| { m.get("/").handle(Handler::new_ready(|_| "Hello")); }) .modifier(RequestCounter::default()) // <-- .finish() .unwrap();
Structs
AfterHandle |
The type representing a return value from |
BeforeHandle |
The type representing a return value from |
Traits
Modifier |
A trait representing a |