diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-07-15 23:31:24 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-07-20 09:08:50 -0700 |
| commit | 7e9e3896dfcef4852ca8ad90f91baf5187b0248e (patch) | |
| tree | 105314b0a9e49abc7727c38c2dff96fd8d454545 /src/libstd/net | |
| parent | 4e51763e6428580f2b3275cd7076492376801a1e (diff) | |
| download | rust-7e9e3896dfcef4852ca8ad90f91baf5187b0248e.tar.gz rust-7e9e3896dfcef4852ca8ad90f91baf5187b0248e.zip | |
std: Add IntoRaw{Fd,Handle,Socket} traits
This commit is an implementation of [RFC 1174][rfc] which adds three new traits to the standard library: * `IntoRawFd` - implemented on Unix for all I/O types (files, sockets, etc) * `IntoRawHandle` - implemented on Windows for files, processes, etc * `IntoRawSocket` - implemented on Windows for networking types [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1174-into-raw-fd-socket-handle-traits.md Closes #27062
Diffstat (limited to 'src/libstd/net')
| -rw-r--r-- | src/libstd/net/tcp.rs | 12 | ||||
| -rw-r--r-- | src/libstd/net/udp.rs | 6 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index 66c8403b268..c410233df92 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -17,9 +17,9 @@ use io::prelude::*; use fmt; use io; use net::{ToSocketAddrs, SocketAddr, Shutdown}; -use sys_common::net as net_imp; -use sys_common::{AsInner, FromInner}; use sys_common::io::read_to_end_uninitialized; +use sys_common::net as net_imp; +use sys_common::{AsInner, FromInner, IntoInner}; use time::Duration; /// A structure which represents a TCP stream between a local socket and a @@ -220,6 +220,10 @@ impl FromInner<net_imp::TcpStream> for TcpStream { fn from_inner(inner: net_imp::TcpStream) -> TcpStream { TcpStream(inner) } } +impl IntoInner<net_imp::TcpStream> for TcpStream { + fn into_inner(self) -> net_imp::TcpStream { self.0 } +} + impl fmt::Debug for TcpStream { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.0.fmt(f) @@ -298,6 +302,10 @@ impl FromInner<net_imp::TcpListener> for TcpListener { } } +impl IntoInner<net_imp::TcpListener> for TcpListener { + fn into_inner(self) -> net_imp::TcpListener { self.0 } +} + impl fmt::Debug for TcpListener { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.0.fmt(f) diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index 0545175d9ae..a98ccc38735 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -17,7 +17,7 @@ use fmt; use io::{self, Error, ErrorKind}; use net::{ToSocketAddrs, SocketAddr, IpAddr}; use sys_common::net as net_imp; -use sys_common::{AsInner, FromInner}; +use sys_common::{AsInner, FromInner, IntoInner}; use time::Duration; /// A User Datagram Protocol socket. @@ -174,6 +174,10 @@ impl FromInner<net_imp::UdpSocket> for UdpSocket { fn from_inner(inner: net_imp::UdpSocket) -> UdpSocket { UdpSocket(inner) } } +impl IntoInner<net_imp::UdpSocket> for UdpSocket { + fn into_inner(self) -> net_imp::UdpSocket { self.0 } +} + impl fmt::Debug for UdpSocket { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.0.fmt(f) |
