monolake_services/common/
erase.rs1use service_async::{
2 layer::{layer_fn, FactoryLayer},
3 AsyncMakeService, MakeService, Service,
4};
5
6#[derive(Debug)]
7pub struct EraseResp<T> {
8 pub svc: T,
9}
10
11impl<T: MakeService> MakeService for EraseResp<T> {
12 type Service = EraseResp<T::Service>;
13 type Error = T::Error;
14
15 #[inline]
16 fn make_via_ref(&self, old: Option<&Self::Service>) -> Result<Self::Service, Self::Error> {
17 Ok(EraseResp {
18 svc: self
19 .svc
20 .make_via_ref(old.map(|o| &o.svc))
21 .map_err(Into::into)?,
22 })
23 }
24}
25
26impl<T: AsyncMakeService> AsyncMakeService for EraseResp<T> {
27 type Service = EraseResp<T::Service>;
28 type Error = T::Error;
29
30 #[inline]
31 async fn make_via_ref(
32 &self,
33 old: Option<&Self::Service>,
34 ) -> Result<Self::Service, Self::Error> {
35 Ok(EraseResp {
36 svc: self
37 .svc
38 .make_via_ref(old.map(|o| &o.svc))
39 .await
40 .map_err(Into::into)?,
41 })
42 }
43}
44
45impl<T: Service<Req>, Req> Service<Req> for EraseResp<T> {
46 type Response = ();
47 type Error = T::Error;
48
49 #[inline]
50 async fn call(&self, req: Req) -> Result<Self::Response, Self::Error> {
51 self.svc.call(req).await.map(|_| ())
52 }
53}
54
55impl<F> EraseResp<F> {
56 pub fn layer<C>() -> impl FactoryLayer<C, F, Factory = Self> {
57 layer_fn(|_c: &C, svc| EraseResp { svc })
58 }
59}
60
61impl<T> EraseResp<T> {
62 #[inline]
63 pub const fn new(svc: T) -> Self {
64 Self { svc }
65 }
66
67 #[inline]
68 pub fn into_inner(self) -> T {
69 self.svc
70 }
71}