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