Implement Debug for std::net::{UdpSocket,TcpStream,TcpListener,Shutdown}
Fixes #23134.
This commit is contained in:
parent
84f8c257b4
commit
3a4a1e5f38
4 changed files with 50 additions and 1 deletions
|
|
@ -32,7 +32,7 @@ mod parser;
|
|||
|
||||
/// Possible values which can be passed to the `shutdown` method of `TcpStream`
|
||||
/// and `UdpSocket`.
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub enum Shutdown {
|
||||
/// Indicates that the reading portion of this stream/socket should be shut
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
use prelude::v1::*;
|
||||
use io::prelude::*;
|
||||
|
||||
use fmt;
|
||||
use io;
|
||||
use net::{ToSocketAddrs, SocketAddr, Shutdown};
|
||||
use sys_common::net2 as net_imp;
|
||||
|
|
@ -167,6 +168,12 @@ impl FromInner<net_imp::TcpStream> for TcpStream {
|
|||
fn from_inner(inner: net_imp::TcpStream) -> TcpStream { TcpStream(inner) }
|
||||
}
|
||||
|
||||
impl fmt::Debug for TcpStream {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl TcpListener {
|
||||
/// Creates a new `TcpListener` which will be bound to the specified
|
||||
/// address.
|
||||
|
|
@ -239,6 +246,12 @@ impl FromInner<net_imp::TcpListener> for TcpListener {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for TcpListener {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use prelude::v1::*;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
use prelude::v1::*;
|
||||
|
||||
use fmt;
|
||||
use io::{self, Error, ErrorKind};
|
||||
use net::{ToSocketAddrs, SocketAddr, IpAddr};
|
||||
use sys_common::net2 as net_imp;
|
||||
|
|
@ -136,6 +137,12 @@ impl FromInner<net_imp::UdpSocket> for UdpSocket {
|
|||
fn from_inner(inner: net_imp::UdpSocket) -> UdpSocket { UdpSocket(inner) }
|
||||
}
|
||||
|
||||
impl fmt::Debug for UdpSocket {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use prelude::v1::*;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
use prelude::v1::*;
|
||||
|
||||
use ffi::{CStr, CString};
|
||||
use fmt;
|
||||
use io::{self, Error, ErrorKind};
|
||||
use libc::{self, c_int, c_char, c_void, socklen_t};
|
||||
use mem;
|
||||
|
|
@ -268,6 +269,16 @@ impl FromInner<Socket> for TcpStream {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for TcpStream {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("TcpStream")
|
||||
.field("addr", &self.socket_addr())
|
||||
.field("peer", &self.peer_addr())
|
||||
.field("inner", &self.inner.as_inner())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TCP listeners
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -327,6 +338,15 @@ impl FromInner<Socket> for TcpListener {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for TcpListener {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("TcpListener")
|
||||
.field("addr", &self.socket_addr())
|
||||
.field("inner", &self.inner.as_inner())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// UDP
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -445,3 +465,12 @@ impl FromInner<Socket> for UdpSocket {
|
|||
UdpSocket { inner: socket }
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for UdpSocket {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("UdpSocket")
|
||||
.field("addr", &self.socket_addr())
|
||||
.field("inner", &self.inner.as_inner())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue