use crate::*;
pub struct Connector {
inner: ConnectorType,
}
enum ConnectorType {
Tcp(TcpConnector),
#[cfg(any(feature = "boringssl", feature = "openssl"))]
TlsTcp(TlsTcpConnector),
}
impl Connector {
pub fn connect<A: ToSocketAddrs>(&self, addr: A) -> Result<Stream> {
match &self.inner {
ConnectorType::Tcp(connector) => Ok(Stream::from(connector.connect(addr)?)),
#[cfg(any(feature = "boringssl", feature = "openssl"))]
ConnectorType::TlsTcp(connector) => Ok(Stream::from(connector.connect(addr)?)),
}
}
}
impl From<TcpConnector> for Connector {
fn from(other: TcpConnector) -> Self {
Self {
inner: ConnectorType::Tcp(other),
}
}
}
#[cfg(any(feature = "boringssl", feature = "openssl"))]
impl From<TlsTcpConnector> for Connector {
fn from(other: TlsTcpConnector) -> Self {
Self {
inner: ConnectorType::TlsTcp(other),
}
}
}