teo_runtime/middleware/
middleware.rs

1use std::sync::Arc;
2use futures_util::future::BoxFuture;
3use crate::middleware::middleware_imp::MiddlewareImp;
4use crate::middleware::next::Next;
5use crate::request::Request;
6use crate::response::Response;
7use teo_result::Result;
8
9#[derive(Clone)]
10#[repr(transparent)]
11pub struct Middleware {
12    pub imp: Arc<dyn MiddlewareImp>,
13}
14
15impl Middleware {
16
17    #[inline]
18    pub fn new<F>(f: F) -> Self where F: MiddlewareImp + 'static {
19        Self {
20            imp: Arc::new(f),
21        }
22    }
23}
24
25impl MiddlewareImp for Middleware {
26    fn call(&self, request: Request, next: Next) -> BoxFuture<'static, Result<Response>> {
27        self.imp.call(request, next)
28    }
29}