1use std::future::Future;
2
3use crate::{Endpoint, Request, Result};
4
5pub struct Before<E, F> {
7 inner: E,
8 f: F,
9}
10
11impl<E, F> Before<E, F> {
12 #[inline]
13 pub(crate) fn new(inner: E, f: F) -> Before<E, F> {
14 Self { inner, f }
15 }
16}
17
18impl<E, F, Fut> Endpoint for Before<E, F>
19where
20 E: Endpoint,
21 F: Fn(Request) -> Fut + Send + Sync,
22 Fut: Future<Output = Result<Request>> + Send,
23{
24 type Output = E::Output;
25
26 async fn call(&self, req: Request) -> Result<Self::Output> {
27 self.inner.call((self.f)(req).await?).await
28 }
29}