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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#![deny(rust_2018_idioms, nonstandard_style)]
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
};
mod boxed;
mod ext;
mod factory;
mod fn_service;
mod map;
mod then;
pub use boxed::{box_svc, BoxFut, BoxSvc};
pub use ext::SvcExt;
pub use fn_service::FnSvc;
pub use map::MapSvc;
pub use then::ThenSvc;
pub trait Svc<Req> {
type Res;
type Fut: Future<Output = Self::Res>;
#[allow(unused_variables)]
fn poll_ready(self: Pin<&mut Self>, cx: Context<'_>) -> Poll<()> {
Poll::Ready(())
}
fn exec(self: Pin<&mut Self>, req: Req) -> Self::Fut;
}
impl<S, Req> Svc<Req> for Box<S>
where
S: Svc<Req>,
{
type Res = S::Res;
type Fut = S::Fut;
fn poll_ready(mut self: Pin<&mut Self>, cx: Context<'_>) -> Poll<()> {
self.as_mut().poll_ready(cx)
}
fn exec(mut self: Pin<&mut Self>, req: Req) -> Self::Fut {
self.as_mut().exec(req)
}
}