File tree 1 file changed +26
-0
lines changed
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -245,6 +245,32 @@ impl AsFd for OwnedFd {
245
245
}
246
246
}
247
247
248
+ macro_rules! impl_owned_fd_traits {
249
+ ( $( $t: ident) * ) => { $(
250
+ impl AsFd for net:: $t {
251
+ #[ inline]
252
+ fn as_fd( & self ) -> BorrowedFd <' _> {
253
+ unsafe { BorrowedFd :: borrow_raw( self . as_raw_fd( ) ) }
254
+ }
255
+ }
256
+
257
+ impl From <net:: $t> for OwnedFd {
258
+ #[ inline]
259
+ fn from( socket: net:: $t) -> OwnedFd {
260
+ unsafe { Self :: from_raw_fd( socket. into_raw_fd( ) ) }
261
+ }
262
+ }
263
+
264
+ impl From <OwnedFd > for net:: $t {
265
+ #[ inline]
266
+ fn from( owned_fd: OwnedFd ) -> Self {
267
+ unsafe { Self :: from_raw_fd( owned_fd. into_raw_fd( ) ) }
268
+ }
269
+ }
270
+ ) * } ;
271
+ }
272
+ impl_owned_fd_traits ! { TcpStream TcpListener UdpSocket }
273
+
248
274
/// A trait to extract the raw SOLID Sockets file descriptor from an underlying
249
275
/// object.
250
276
pub trait AsRawFd {
You can’t perform that action at this time.
0 commit comments