30
30
#![ deny( missing_docs) ]
31
31
#![ cfg_attr( rustc_attrs, feature( rustc_attrs) ) ]
32
32
#![ cfg_attr( target_os = "wasi" , feature( wasi_ext) ) ]
33
+ #![ cfg_attr( io_lifetimes_use_std, feature( io_safety) ) ]
33
34
34
35
mod portability;
35
36
mod traits;
37
+ #[ cfg( not( io_lifetimes_use_std) ) ]
36
38
mod types;
37
39
40
+ #[ cfg( not( io_lifetimes_use_std) ) ]
41
+ mod impls_std;
42
+
43
+ #[ cfg( not( io_lifetimes_use_std) ) ]
44
+ #[ cfg( any( unix, target_os = "wasi" ) ) ]
45
+ pub use traits:: AsFd ;
46
+ #[ cfg( not( io_lifetimes_use_std) ) ]
47
+ #[ cfg( windows) ]
48
+ pub use traits:: { AsHandle , AsSocket } ;
38
49
#[ cfg( any( unix, target_os = "wasi" ) ) ]
39
- pub use traits:: { AsFd , FromFd , IntoFd } ;
50
+ pub use traits:: { FromFd , IntoFd } ;
40
51
#[ cfg( windows) ]
41
- pub use traits:: { AsHandle , AsSocket , FromHandle , FromSocket , IntoHandle , IntoSocket } ;
52
+ pub use traits:: { FromHandle , FromSocket , IntoHandle , IntoSocket } ;
42
53
54
+ #[ cfg( not( io_lifetimes_use_std) ) ]
43
55
#[ cfg( any( unix, target_os = "wasi" ) ) ]
44
56
pub use types:: { BorrowedFd , OwnedFd } ;
57
+ #[ cfg( not( io_lifetimes_use_std) ) ]
45
58
#[ cfg( windows) ]
46
59
pub use types:: { BorrowedHandle , BorrowedSocket , HandleOrInvalid , OwnedHandle , OwnedSocket } ;
47
60
61
+ #[ cfg( io_lifetimes_use_std) ]
62
+ #[ cfg( unix) ]
63
+ pub use std:: os:: unix:: io:: { AsFd , BorrowedFd , OwnedFd } ;
64
+ #[ cfg( io_lifetimes_use_std) ]
65
+ #[ cfg( target_os = "wasi" ) ]
66
+ pub use std:: os:: wasi:: io:: { AsFd , BorrowedFd , OwnedFd } ;
67
+ #[ cfg( io_lifetimes_use_std) ]
68
+ #[ cfg( windows) ]
69
+ pub use std:: os:: windows:: io:: {
70
+ AsHandle , AsSocket , BorrowedHandle , BorrowedSocket , HandleOrInvalid , OwnedHandle , OwnedSocket ,
71
+ } ;
72
+
73
+ // io-lifetimes defined `FromFd`/`IntoFd` traits instead of just using
74
+ // `From`/`Into` because that allowed it to implement them for foreign types,
75
+ // including std types like File and TcpStream, and popular third-party types.
76
+ //
77
+ // std just uses `From`/`Into`, because it defines those traits itself so it
78
+ // can implement them for std types itself, and std won't be implementing them
79
+ // for third-party types. However, this means that until `OwnedFd` et al are
80
+ // stabilized, there will be no impls for third-party traits.
81
+ //
82
+ // So we define `FromFd`/`IntoFd` traits, and implement them in terms of
83
+ // `From`/`Into`,
84
+ #[ cfg( io_lifetimes_use_std) ]
85
+ #[ cfg( any( unix, target_os = "wasi" ) ) ]
86
+ impl < T : From < OwnedFd > > FromFd for T {
87
+ #[ inline]
88
+ fn from_fd ( owned_fd : OwnedFd ) -> Self {
89
+ owned_fd. into ( )
90
+ }
91
+ }
92
+ #[ cfg( io_lifetimes_use_std) ]
93
+ #[ cfg( any( unix, target_os = "wasi" ) ) ]
94
+ impl < T > IntoFd for T
95
+ where
96
+ OwnedFd : From < T > ,
97
+ {
98
+ #[ inline]
99
+ fn into_fd ( self ) -> OwnedFd {
100
+ self . into ( )
101
+ }
102
+ }
103
+
104
+ #[ cfg( io_lifetimes_use_std) ]
105
+ #[ cfg( windows) ]
106
+ impl < T : From < OwnedHandle > > FromHandle for T {
107
+ #[ inline]
108
+ fn from_handle ( owned_handle : OwnedHandle ) -> Self {
109
+ owned_handle. into ( )
110
+ }
111
+ }
112
+ #[ cfg( io_lifetimes_use_std) ]
113
+ #[ cfg( windows) ]
114
+ impl < T > IntoHandle for T
115
+ where
116
+ OwnedHandle : From < T > ,
117
+ {
118
+ #[ inline]
119
+ fn into_handle ( self ) -> OwnedHandle {
120
+ self . into ( )
121
+ }
122
+ }
123
+
124
+ #[ cfg( io_lifetimes_use_std) ]
125
+ #[ cfg( windows) ]
126
+ impl < T : From < OwnedSocket > > FromSocket for T {
127
+ #[ inline]
128
+ fn from_socket ( owned_socket : OwnedSocket ) -> Self {
129
+ owned_socket. into ( )
130
+ }
131
+ }
132
+ #[ cfg( io_lifetimes_use_std) ]
133
+ #[ cfg( windows) ]
134
+ impl < T > IntoSocket for T
135
+ where
136
+ OwnedSocket : From < T > ,
137
+ {
138
+ #[ inline]
139
+ fn into_socket ( self ) -> OwnedSocket {
140
+ self . into ( )
141
+ }
142
+ }
143
+
48
144
pub use portability:: {
49
145
AsFilelike , AsSocketlike , BorrowedFilelike , BorrowedSocketlike , FromFilelike , FromSocketlike ,
50
146
IntoFilelike , IntoSocketlike , OwnedFilelike , OwnedSocketlike ,
@@ -56,15 +152,21 @@ pub mod views;
56
152
57
153
// Ideally, we'd want crates to implement our traits themselves. But for now,
58
154
// while we're prototyping, we provide a few impls on foreign types.
155
+ #[ cfg( not( io_lifetimes_use_std) ) ]
59
156
#[ cfg( feature = "async-std" ) ]
60
157
mod impls_async_std;
158
+ #[ cfg( not( io_lifetimes_use_std) ) ]
61
159
#[ cfg( feature = "fs-err" ) ]
62
160
mod impls_fs_err;
161
+ #[ cfg( not( io_lifetimes_use_std) ) ]
63
162
#[ cfg( feature = "mio" ) ]
64
163
mod impls_mio;
164
+ #[ cfg( not( io_lifetimes_use_std) ) ]
65
165
#[ cfg( feature = "os_pipe" ) ]
66
166
mod impls_os_pipe;
167
+ #[ cfg( not( io_lifetimes_use_std) ) ]
67
168
#[ cfg( feature = "socket2" ) ]
68
169
mod impls_socket2;
170
+ #[ cfg( not( io_lifetimes_use_std) ) ]
69
171
#[ cfg( feature = "tokio" ) ]
70
172
mod impls_tokio;
0 commit comments