Skip to main content

alpine/
middleware.rs

1use std::future::Future;
2use std::pin::Pin;
3use std::sync::Arc;
4
5use crate::error::ProviderError;
6use crate::types::{Request, Response};
7
8/// The rest of the middleware chain + provider call.
9pub type Next = Box<
10    dyn FnOnce(Request) -> Pin<Box<dyn Future<Output = Result<Response, ProviderError>> + Send>>
11        + Send,
12>;
13
14/// Middleware that can inspect / transform a request before it reaches the
15/// provider and the response after it comes back.
16pub trait Middleware: Send + Sync + 'static {
17    fn handle(
18        self: Arc<Self>,
19        req: Request,
20        next: Next,
21    ) -> Pin<Box<dyn Future<Output = Result<Response, ProviderError>> + Send>>;
22}