Skip to content

Commit a14d696

Browse files
committed
Auto merge of rust-lang#108196 - sunfishcode:sunfishcode/windows-as-socket-impls, r=dtolnay
Implement `AsHandle`/`AsSocket` for `Arc`/`Rc`/`Box` on Windows Implement the Windows counterpart to rust-lang#97437 and rust-lang#107317: Implement `AsHandle` and `AsSocket` for `Arc<T>`, `Rc<T>`, and `Box<T>`.
2 parents 18bfe5d + a117c50 commit a14d696

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

library/std/src/os/windows/io/handle.rs

+36
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,42 @@ impl<T: AsHandle> AsHandle for &mut T {
437437
}
438438
}
439439

440+
#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")]
441+
/// This impl allows implementing traits that require `AsHandle` on Arc.
442+
/// ```
443+
/// # #[cfg(windows)] mod group_cfg {
444+
/// # use std::os::windows::io::AsHandle;
445+
/// use std::fs::File;
446+
/// use std::sync::Arc;
447+
///
448+
/// trait MyTrait: AsHandle {}
449+
/// impl MyTrait for Arc<File> {}
450+
/// impl MyTrait for Box<File> {}
451+
/// # }
452+
/// ```
453+
impl<T: AsHandle> AsHandle for crate::sync::Arc<T> {
454+
#[inline]
455+
fn as_handle(&self) -> BorrowedHandle<'_> {
456+
(**self).as_handle()
457+
}
458+
}
459+
460+
#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")]
461+
impl<T: AsHandle> AsHandle for crate::rc::Rc<T> {
462+
#[inline]
463+
fn as_handle(&self) -> BorrowedHandle<'_> {
464+
(**self).as_handle()
465+
}
466+
}
467+
468+
#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")]
469+
impl<T: AsHandle> AsHandle for Box<T> {
470+
#[inline]
471+
fn as_handle(&self) -> BorrowedHandle<'_> {
472+
(**self).as_handle()
473+
}
474+
}
475+
440476
#[stable(feature = "io_safety", since = "1.63.0")]
441477
impl AsHandle for BorrowedHandle<'_> {
442478
#[inline]

library/std/src/os/windows/io/socket.rs

+36
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,42 @@ impl<T: AsSocket> AsSocket for &mut T {
254254
}
255255
}
256256

257+
#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")]
258+
/// This impl allows implementing traits that require `AsSocket` on Arc.
259+
/// ```
260+
/// # #[cfg(windows)] mod group_cfg {
261+
/// # use std::os::windows::io::AsSocket;
262+
/// use std::net::UdpSocket;
263+
/// use std::sync::Arc;
264+
///
265+
/// trait MyTrait: AsSocket {}
266+
/// impl MyTrait for Arc<UdpSocket> {}
267+
/// impl MyTrait for Box<UdpSocket> {}
268+
/// # }
269+
/// ```
270+
impl<T: AsSocket> AsSocket for crate::sync::Arc<T> {
271+
#[inline]
272+
fn as_socket(&self) -> BorrowedSocket<'_> {
273+
(**self).as_socket()
274+
}
275+
}
276+
277+
#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")]
278+
impl<T: AsSocket> AsSocket for crate::rc::Rc<T> {
279+
#[inline]
280+
fn as_socket(&self) -> BorrowedSocket<'_> {
281+
(**self).as_socket()
282+
}
283+
}
284+
285+
#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")]
286+
impl<T: AsSocket> AsSocket for Box<T> {
287+
#[inline]
288+
fn as_socket(&self) -> BorrowedSocket<'_> {
289+
(**self).as_socket()
290+
}
291+
}
292+
257293
#[stable(feature = "io_safety", since = "1.63.0")]
258294
impl AsSocket for BorrowedSocket<'_> {
259295
#[inline]

0 commit comments

Comments
 (0)