1use super::*;
3
4use tokio::net::{TcpStream, ToSocketAddrs};
5
6pub struct TcpConnector<A>(A);
8
9impl<A> TcpConnector<A> {
10 pub fn new(address: A) -> Self {
11 Self(address)
12 }
13
14 #[inline]
16 pub fn get_addr(&self) -> &A {
17 &self.0
18 }
19
20 #[inline]
22 pub fn get_addr_mut(&mut self) -> &mut A {
23 &mut self.0
24 }
25}
26
27impl<A, R> Tether<TcpConnector<A>, R>
28where
29 R: Resolver<TcpConnector<A>>,
30 A: 'static + ToSocketAddrs + Clone + Send + Sync,
31{
32 pub async fn connect_tcp(address: A, resolver: R) -> Result<Self, std::io::Error> {
34 let connector = TcpConnector::new(address);
35 Tether::connect(connector, resolver).await
36 }
37}
38
39impl<A> Io for TcpConnector<A>
40where
41 A: 'static + ToSocketAddrs + Clone + Send + Sync,
42{
43 type Output = TcpStream;
44
45 fn connect(&mut self) -> PinFut<Result<Self::Output, std::io::Error>> {
46 let address = self.0.clone();
47 Box::pin(TcpStream::connect(address))
48 }
49}