Skip to content

Commit a117c50

Browse files
committed
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>`.
1 parent 9aa5c24 commit a117c50

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
@@ -247,6 +247,42 @@ impl<T: AsSocket> AsSocket for &mut T {
247247
}
248248
}
249249

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

0 commit comments

Comments
 (0)