@@ -12,6 +12,8 @@ use std::fmt;
12
12
use std:: io:: { self , Read , Write } ;
13
13
use std:: net:: { self , Ipv4Addr , Ipv6Addr , Shutdown } ;
14
14
use std:: time:: Duration ;
15
+ #[ cfg( all( unix, feature = "unix" ) ) ]
16
+ use std:: os:: unix:: net:: { UnixDatagram , UnixListener , UnixStream } ;
15
17
16
18
#[ cfg( unix) ]
17
19
use libc as c;
@@ -66,6 +68,33 @@ impl Socket {
66
68
self . into ( )
67
69
}
68
70
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
+
69
98
/// Initiate a connection on this socket to the specified address.
70
99
///
71
100
/// This function directly corresponds to the connect(2) function on Windows
@@ -614,6 +643,27 @@ impl From<net::UdpSocket> for Socket {
614
643
}
615
644
}
616
645
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
+
617
667
impl From < Socket > for net:: TcpStream {
618
668
fn from ( socket : Socket ) -> net:: TcpStream {
619
669
socket. inner . into ( )
@@ -632,6 +682,27 @@ impl From<Socket> for net::UdpSocket {
632
682
}
633
683
}
634
684
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
+
635
706
impl Domain {
636
707
/// Domain for IPv4 communication, corresponding to `AF_INET`.
637
708
pub fn ipv4 ( ) -> Domain {
0 commit comments