boluo_core/service/
map_request.rs1use super::Service;
2
3#[derive(Clone, Copy)]
7pub struct MapRequest<S, F> {
8 service: S,
9 f: F,
10}
11
12impl<S, F> MapRequest<S, F> {
13 pub fn new(service: S, f: F) -> Self {
15 Self { service, f }
16 }
17}
18
19impl<S, F, R1, R2> Service<R1> for MapRequest<S, F>
20where
21 S: Service<R2>,
22 F: Fn(R1) -> R2 + Send + Sync,
23{
24 type Response = S::Response;
25 type Error = S::Error;
26
27 fn call(&self, req: R1) -> impl Future<Output = Result<Self::Response, Self::Error>> + Send {
28 self.service.call((self.f)(req))
29 }
30}
31
32impl<S, F> std::fmt::Debug for MapRequest<S, F>
33where
34 S: std::fmt::Debug,
35{
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 f.debug_struct("MapRequest")
38 .field("service", &self.service)
39 .field("f", &std::any::type_name::<F>())
40 .finish()
41 }
42}