tower/make/
make_connection.rs1use crate::sealed::Sealed;
2use std::future::Future;
3use std::task::{Context, Poll};
4use tokio::io::{AsyncRead, AsyncWrite};
5use tower_service::Service;
6
7pub trait MakeConnection<Target>: Sealed<(Target,)> {
13 type Connection: AsyncRead + AsyncWrite;
15
16 type Error;
18
19 type Future: Future<Output = Result<Self::Connection, Self::Error>>;
21
22 fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;
24
25 fn make_connection(&mut self, target: Target) -> Self::Future;
27}
28
29impl<S, Target> Sealed<(Target,)> for S where S: Service<Target> {}
30
31impl<C, Target> MakeConnection<Target> for C
32where
33 C: Service<Target>,
34 C::Response: AsyncRead + AsyncWrite,
35{
36 type Connection = C::Response;
37 type Error = C::Error;
38 type Future = C::Future;
39
40 fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
41 Service::poll_ready(self, cx)
42 }
43
44 fn make_connection(&mut self, target: Target) -> Self::Future {
45 Service::call(self, target)
46 }
47}