use std::io::{Read, Result as IoResult, Write};
use std::net::TcpStream;
pub(crate) enum Transport {
Plain(TcpStream),
#[cfg(feature = "tls")]
Tls(Box<rustls::StreamOwned<rustls::ClientConnection, TcpStream>>),
}
impl Transport {
pub(crate) fn tcp(&self) -> &TcpStream {
match self {
Self::Plain(s) => s,
#[cfg(feature = "tls")]
Self::Tls(s) => &s.sock,
}
}
}
impl Read for Transport {
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> {
match self {
Self::Plain(s) => s.read(buf),
#[cfg(feature = "tls")]
Self::Tls(s) => s.read(buf),
}
}
}
impl Write for Transport {
fn write(&mut self, buf: &[u8]) -> IoResult<usize> {
match self {
Self::Plain(s) => s.write(buf),
#[cfg(feature = "tls")]
Self::Tls(s) => s.write(buf),
}
}
fn flush(&mut self) -> IoResult<()> {
match self {
Self::Plain(s) => s.flush(),
#[cfg(feature = "tls")]
Self::Tls(s) => s.flush(),
}
}
}