maik 0.2.0

A mock SMTP server library
Documentation
use native_tls::TlsStream;
use std::fmt::Debug;
use std::io::{self, Read, Write};
use std::net::{Shutdown, TcpStream};

#[derive(Debug)]
pub enum Stream {
    Plain(TcpStream),
    Tls(TlsStream<TcpStream>),
}

impl Stream {
    pub fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
        match self {
            Stream::Plain(stream) => stream.read(buf),
            Stream::Tls(stream) => stream.read(buf),
        }
    }

    pub fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
        match self {
            Stream::Plain(stream) => stream.write_all(buf),
            Stream::Tls(stream) => stream.write_all(buf),
        }
    }

    pub fn shutdown(&mut self) -> io::Result<()> {
        match self {
            Stream::Plain(stream) => stream.shutdown(Shutdown::Both),
            Stream::Tls(stream) => stream.shutdown(),
        }
    }
}