Skip to content

Commit

Permalink
Auto merge of rust-lang#108196 - sunfishcode:sunfishcode/windows-as-s…
Browse files Browse the repository at this point in the history
…ocket-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>`.
  • Loading branch information
bors committed May 14, 2023
2 parents 18bfe5d + a117c50 commit a14d696
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
36 changes: 36 additions & 0 deletions library/std/src/os/windows/io/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,42 @@ impl<T: AsHandle> AsHandle for &mut T {
}
}

#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")]
/// This impl allows implementing traits that require `AsHandle` on Arc.
/// ```
/// # #[cfg(windows)] mod group_cfg {
/// # use std::os::windows::io::AsHandle;
/// use std::fs::File;
/// use std::sync::Arc;
///
/// trait MyTrait: AsHandle {}
/// impl MyTrait for Arc<File> {}
/// impl MyTrait for Box<File> {}
/// # }
/// ```
impl<T: AsHandle> AsHandle for crate::sync::Arc<T> {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
(**self).as_handle()
}
}

#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")]
impl<T: AsHandle> AsHandle for crate::rc::Rc<T> {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
(**self).as_handle()
}
}

#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")]
impl<T: AsHandle> AsHandle for Box<T> {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
(**self).as_handle()
}
}

#[stable(feature = "io_safety", since = "1.63.0")]
impl AsHandle for BorrowedHandle<'_> {
#[inline]
Expand Down
36 changes: 36 additions & 0 deletions library/std/src/os/windows/io/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,42 @@ impl<T: AsSocket> AsSocket for &mut T {
}
}

#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")]
/// This impl allows implementing traits that require `AsSocket` on Arc.
/// ```
/// # #[cfg(windows)] mod group_cfg {
/// # use std::os::windows::io::AsSocket;
/// use std::net::UdpSocket;
/// use std::sync::Arc;
///
/// trait MyTrait: AsSocket {}
/// impl MyTrait for Arc<UdpSocket> {}
/// impl MyTrait for Box<UdpSocket> {}
/// # }
/// ```
impl<T: AsSocket> AsSocket for crate::sync::Arc<T> {
#[inline]
fn as_socket(&self) -> BorrowedSocket<'_> {
(**self).as_socket()
}
}

#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")]
impl<T: AsSocket> AsSocket for crate::rc::Rc<T> {
#[inline]
fn as_socket(&self) -> BorrowedSocket<'_> {
(**self).as_socket()
}
}

#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")]
impl<T: AsSocket> AsSocket for Box<T> {
#[inline]
fn as_socket(&self) -> BorrowedSocket<'_> {
(**self).as_socket()
}
}

#[stable(feature = "io_safety", since = "1.63.0")]
impl AsSocket for BorrowedSocket<'_> {
#[inline]
Expand Down

0 comments on commit a14d696

Please sign in to comment.