Require Debug for StreamWrapper

This commit is contained in:
Steven Fackler 2015-12-13 23:27:12 -08:00
parent 2de8ecad6e
commit a6d9a214a6
3 changed files with 13 additions and 1 deletions

View File

@ -11,7 +11,7 @@ mod openssl;
mod security_framework;
/// A trait implemented by SSL adaptors.
pub trait StreamWrapper: Read+Write+Send {
pub trait StreamWrapper: fmt::Debug + Read + Write + Send {
/// Returns a reference to the underlying `Stream`.
fn get_ref(&self) -> &Stream;

View File

@ -826,6 +826,7 @@ impl fmt::Debug for Connection {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let conn = self.conn.borrow();
fmt.debug_struct("Connection")
.field("stream", &conn.stream.get_ref())
.field("cancel_data", &conn.cancel_data)
.field("notifications", &conn.notifications.len())
.field("transaction_depth", &conn.trans_depth)

View File

@ -2,6 +2,7 @@ use byteorder::ReadBytesExt;
use net2::TcpStreamExt;
use std::io;
use std::io::prelude::*;
use std::fmt;
use std::net::TcpStream;
use std::time::Duration;
use bufstream::BufStream;
@ -43,6 +44,16 @@ impl ReadTimeout for BufStream<Box<StreamWrapper>> {
/// Unix platforms and `AsRawSocket` on Windows platforms.
pub struct Stream(InternalStream);
impl fmt::Debug for Stream {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match self.0 {
InternalStream::Tcp(ref s) => fmt::Debug::fmt(s, fmt),
#[cfg(feature = "unix_socket")]
InternalStream::Unix(ref s) => fmt::Debug::fmt(s, fmt),
}
}
}
impl Read for Stream {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.0.read(buf)