mirror of https://github.com/chipsenkbeil/distant
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
665 B
Rust
34 lines
665 B
Rust
use std::io;
|
|
|
|
use async_trait::async_trait;
|
|
use tokio::net::ToSocketAddrs;
|
|
|
|
use super::Connector;
|
|
use crate::common::TcpTransport;
|
|
|
|
/// Implementation of [`Connector`] to support connecting via TCP.
|
|
pub struct TcpConnector<T> {
|
|
addr: T,
|
|
}
|
|
|
|
impl<T> TcpConnector<T> {
|
|
pub fn new(addr: T) -> Self {
|
|
Self { addr }
|
|
}
|
|
}
|
|
|
|
impl<T> From<T> for TcpConnector<T> {
|
|
fn from(addr: T) -> Self {
|
|
Self::new(addr)
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl<T: ToSocketAddrs + Send> Connector for TcpConnector<T> {
|
|
type Transport = TcpTransport;
|
|
|
|
async fn connect(self) -> io::Result<Self::Transport> {
|
|
TcpTransport::connect(self.addr).await
|
|
}
|
|
}
|