@@ -12,6 +12,8 @@ use std::fmt;
1212use std:: io:: { self , Read , Write } ;
1313use std:: net:: { self , Ipv4Addr , Ipv6Addr , Shutdown } ;
1414use std:: time:: Duration ;
15+ #[ cfg( all( unix, feature = "unix" ) ) ]
16+ use std:: os:: unix:: net:: { UnixDatagram , UnixListener , UnixStream } ;
1517
1618#[ cfg( unix) ]
1719use libc as c;
@@ -66,6 +68,33 @@ impl Socket {
6668 self . into ( )
6769 }
6870
71+ /// Consumes this `Socket`, converting it into a `UnixStream`.
72+ ///
73+ /// This function is only available on Unix when the `unix` feature is
74+ /// enabled.
75+ #[ cfg( all( unix, feature = "unix" ) ) ]
76+ pub fn into_unix_stream ( self ) -> UnixStream {
77+ self . into ( )
78+ }
79+
80+ /// Consumes this `Socket`, converting it into a `UnixListener`.
81+ ///
82+ /// This function is only available on Unix when the `unix` feature is
83+ /// enabled.
84+ #[ cfg( all( unix, feature = "unix" ) ) ]
85+ pub fn into_unix_listener ( self ) -> UnixListener {
86+ self . into ( )
87+ }
88+
89+ /// Consumes this `Socket`, converting it into a `UnixDatagram`.
90+ ///
91+ /// This function is only available on Unix when the `unix` feature is
92+ /// enabled.
93+ #[ cfg( all( unix, feature = "unix" ) ) ]
94+ pub fn into_unix_datagram ( self ) -> UnixDatagram {
95+ self . into ( )
96+ }
97+
6998 /// Initiate a connection on this socket to the specified address.
7099 ///
71100 /// This function directly corresponds to the connect(2) function on Windows
@@ -614,6 +643,27 @@ impl From<net::UdpSocket> for Socket {
614643 }
615644}
616645
646+ #[ cfg( all( unix, feature = "unix" ) ) ]
647+ impl From < UnixStream > for Socket {
648+ fn from ( socket : UnixStream ) -> Socket {
649+ Socket { inner : socket. into ( ) }
650+ }
651+ }
652+
653+ #[ cfg( all( unix, feature = "unix" ) ) ]
654+ impl From < UnixListener > for Socket {
655+ fn from ( socket : UnixListener ) -> Socket {
656+ Socket { inner : socket. into ( ) }
657+ }
658+ }
659+
660+ #[ cfg( all( unix, feature = "unix" ) ) ]
661+ impl From < UnixDatagram > for Socket {
662+ fn from ( socket : UnixDatagram ) -> Socket {
663+ Socket { inner : socket. into ( ) }
664+ }
665+ }
666+
617667impl From < Socket > for net:: TcpStream {
618668 fn from ( socket : Socket ) -> net:: TcpStream {
619669 socket. inner . into ( )
@@ -632,6 +682,27 @@ impl From<Socket> for net::UdpSocket {
632682 }
633683}
634684
685+ #[ cfg( all( unix, feature = "unix" ) ) ]
686+ impl From < Socket > for UnixStream {
687+ fn from ( socket : Socket ) -> UnixStream {
688+ socket. inner . into ( )
689+ }
690+ }
691+
692+ #[ cfg( all( unix, feature = "unix" ) ) ]
693+ impl From < Socket > for UnixListener {
694+ fn from ( socket : Socket ) -> UnixListener {
695+ socket. inner . into ( )
696+ }
697+ }
698+
699+ #[ cfg( all( unix, feature = "unix" ) ) ]
700+ impl From < Socket > for UnixDatagram {
701+ fn from ( socket : Socket ) -> UnixDatagram {
702+ socket. inner . into ( )
703+ }
704+ }
705+
635706impl Domain {
636707 /// Domain for IPv4 communication, corresponding to `AF_INET`.
637708 pub fn ipv4 ( ) -> Domain {
0 commit comments