Drop MaybeSslStream
It should be inlined into crates that depend on it.
This commit is contained in:
parent
085b2e6f03
commit
00f517d2cd
|
|
@ -1295,64 +1295,3 @@ impl<'a> IntoSsl for &'a SslContext {
|
|||
Ssl::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// A utility type to help in cases where the use of SSL is decided at runtime.
|
||||
#[derive(Debug)]
|
||||
pub enum MaybeSslStream<S>
|
||||
where S: Read + Write
|
||||
{
|
||||
/// A connection using SSL
|
||||
Ssl(SslStream<S>),
|
||||
/// A connection not using SSL
|
||||
Normal(S),
|
||||
}
|
||||
|
||||
impl<S> Read for MaybeSslStream<S> where S: Read + Write
|
||||
{
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
match *self {
|
||||
MaybeSslStream::Ssl(ref mut s) => s.read(buf),
|
||||
MaybeSslStream::Normal(ref mut s) => s.read(buf),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Write for MaybeSslStream<S> where S: Read + Write
|
||||
{
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
match *self {
|
||||
MaybeSslStream::Ssl(ref mut s) => s.write(buf),
|
||||
MaybeSslStream::Normal(ref mut s) => s.write(buf),
|
||||
}
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
match *self {
|
||||
MaybeSslStream::Ssl(ref mut s) => s.flush(),
|
||||
MaybeSslStream::Normal(ref mut s) => s.flush(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> MaybeSslStream<S> where S: Read + Write
|
||||
{
|
||||
/// Returns a reference to the underlying stream.
|
||||
pub fn get_ref(&self) -> &S {
|
||||
match *self {
|
||||
MaybeSslStream::Ssl(ref s) => s.get_ref(),
|
||||
MaybeSslStream::Normal(ref s) => s,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the underlying stream.
|
||||
///
|
||||
/// ## Warning
|
||||
///
|
||||
/// It is inadvisable to read from or write to the underlying stream.
|
||||
pub fn get_mut(&mut self) -> &mut S {
|
||||
match *self {
|
||||
MaybeSslStream::Ssl(ref mut s) => s.get_mut(),
|
||||
MaybeSslStream::Normal(ref mut s) => s,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue