Rollup merge of #120459 - rytheo:handle-conversion-docs, r=Mark-Simulacrum

Document various I/O descriptor/handle conversions

Related to #51430
This commit is contained in:
Matthias Krüger 2024-02-11 08:25:43 +01:00 committed by GitHub
commit 3a198077c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 25 additions and 0 deletions

View File

@ -288,6 +288,7 @@ impl AsFd for fs::File {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<fs::File> for OwnedFd {
/// Takes ownership of a [`File`](fs::File)'s underlying file descriptor.
#[inline]
fn from(file: fs::File) -> OwnedFd {
file.into_inner().into_inner().into_inner()
@ -296,6 +297,8 @@ impl From<fs::File> for OwnedFd {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<OwnedFd> for fs::File {
/// Returns a [`File`](fs::File) that takes ownership of the given
/// file descriptor.
#[inline]
fn from(owned_fd: OwnedFd) -> Self {
Self::from_inner(FromInner::from_inner(FromInner::from_inner(owned_fd)))
@ -312,6 +315,7 @@ impl AsFd for crate::net::TcpStream {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::net::TcpStream> for OwnedFd {
/// Takes ownership of a [`TcpStream`](crate::net::TcpStream)'s socket file descriptor.
#[inline]
fn from(tcp_stream: crate::net::TcpStream) -> OwnedFd {
tcp_stream.into_inner().into_socket().into_inner().into_inner().into()
@ -338,6 +342,7 @@ impl AsFd for crate::net::TcpListener {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::net::TcpListener> for OwnedFd {
/// Takes ownership of a [`TcpListener`](crate::net::TcpListener)'s socket file descriptor.
#[inline]
fn from(tcp_listener: crate::net::TcpListener) -> OwnedFd {
tcp_listener.into_inner().into_socket().into_inner().into_inner().into()
@ -364,6 +369,7 @@ impl AsFd for crate::net::UdpSocket {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::net::UdpSocket> for OwnedFd {
/// Takes ownership of a [`UdpSocket`](crate::net::UdpSocket)'s file descriptor.
#[inline]
fn from(udp_socket: crate::net::UdpSocket) -> OwnedFd {
udp_socket.into_inner().into_socket().into_inner().into_inner().into()

View File

@ -1024,6 +1024,7 @@ impl AsFd for UnixDatagram {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<UnixDatagram> for OwnedFd {
/// Takes ownership of a [`UnixDatagram`]'s socket file descriptor.
#[inline]
fn from(unix_datagram: UnixDatagram) -> OwnedFd {
unsafe { OwnedFd::from_raw_fd(unix_datagram.into_raw_fd()) }

View File

@ -346,6 +346,7 @@ impl From<OwnedFd> for UnixListener {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<UnixListener> for OwnedFd {
/// Takes ownership of a [`UnixListener`]'s socket file descriptor.
#[inline]
fn from(listener: UnixListener) -> OwnedFd {
listener.0.into_inner().into_inner()

View File

@ -752,6 +752,7 @@ impl AsFd for UnixStream {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<UnixStream> for OwnedFd {
/// Takes ownership of a [`UnixStream`]'s socket file descriptor.
#[inline]
fn from(unix_stream: UnixStream) -> OwnedFd {
unsafe { OwnedFd::from_raw_fd(unix_stream.into_raw_fd()) }

View File

@ -362,6 +362,8 @@ impl FromRawFd for process::Stdio {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<OwnedFd> for process::Stdio {
/// Takes ownership of a file descriptor and returns a [`Stdio`](process::Stdio)
/// that can attach a stream to it.
#[inline]
fn from(fd: OwnedFd) -> process::Stdio {
let fd = sys::fd::FileDesc::from_inner(fd);
@ -428,6 +430,7 @@ impl AsFd for crate::process::ChildStdin {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::process::ChildStdin> for OwnedFd {
/// Takes ownership of a [`ChildStdin`](crate::process::ChildStdin)'s file descriptor.
#[inline]
fn from(child_stdin: crate::process::ChildStdin) -> OwnedFd {
child_stdin.into_inner().into_inner().into_inner()
@ -458,6 +461,7 @@ impl AsFd for crate::process::ChildStdout {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::process::ChildStdout> for OwnedFd {
/// Takes ownership of a [`ChildStdout`](crate::process::ChildStdout)'s file descriptor.
#[inline]
fn from(child_stdout: crate::process::ChildStdout) -> OwnedFd {
child_stdout.into_inner().into_inner().into_inner()
@ -488,6 +492,7 @@ impl AsFd for crate::process::ChildStderr {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::process::ChildStderr> for OwnedFd {
/// Takes ownership of a [`ChildStderr`](crate::process::ChildStderr)'s file descriptor.
#[inline]
fn from(child_stderr: crate::process::ChildStderr) -> OwnedFd {
child_stderr.into_inner().into_inner().into_inner()

View File

@ -502,6 +502,7 @@ impl AsHandle for fs::File {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<fs::File> for OwnedHandle {
/// Takes ownership of a [`File`](fs::File)'s underlying file handle.
#[inline]
fn from(file: fs::File) -> OwnedHandle {
file.into_inner().into_inner().into_inner()
@ -510,6 +511,7 @@ impl From<fs::File> for OwnedHandle {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<OwnedHandle> for fs::File {
/// Returns a [`File`](fs::File) that takes ownership of the given handle.
#[inline]
fn from(owned: OwnedHandle) -> Self {
Self::from_inner(FromInner::from_inner(FromInner::from_inner(owned)))
@ -574,6 +576,7 @@ impl AsHandle for crate::process::ChildStdin {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::process::ChildStdin> for OwnedHandle {
/// Takes ownership of a [`ChildStdin`](crate::process::ChildStdin)'s file handle.
#[inline]
fn from(child_stdin: crate::process::ChildStdin) -> OwnedHandle {
unsafe { OwnedHandle::from_raw_handle(child_stdin.into_raw_handle()) }
@ -590,6 +593,7 @@ impl AsHandle for crate::process::ChildStdout {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::process::ChildStdout> for OwnedHandle {
/// Takes ownership of a [`ChildStdout`](crate::process::ChildStdout)'s file handle.
#[inline]
fn from(child_stdout: crate::process::ChildStdout) -> OwnedHandle {
unsafe { OwnedHandle::from_raw_handle(child_stdout.into_raw_handle()) }
@ -606,6 +610,7 @@ impl AsHandle for crate::process::ChildStderr {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::process::ChildStderr> for OwnedHandle {
/// Takes ownership of a [`ChildStderr`](crate::process::ChildStderr)'s file handle.
#[inline]
fn from(child_stderr: crate::process::ChildStderr) -> OwnedHandle {
unsafe { OwnedHandle::from_raw_handle(child_stderr.into_raw_handle()) }

View File

@ -319,6 +319,7 @@ impl AsSocket for crate::net::TcpStream {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::net::TcpStream> for OwnedSocket {
/// Takes ownership of a [`TcpStream`](crate::net::TcpStream)'s socket.
#[inline]
fn from(tcp_stream: crate::net::TcpStream) -> OwnedSocket {
unsafe { OwnedSocket::from_raw_socket(tcp_stream.into_raw_socket()) }
@ -343,6 +344,7 @@ impl AsSocket for crate::net::TcpListener {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::net::TcpListener> for OwnedSocket {
/// Takes ownership of a [`TcpListener`](crate::net::TcpListener)'s socket.
#[inline]
fn from(tcp_listener: crate::net::TcpListener) -> OwnedSocket {
unsafe { OwnedSocket::from_raw_socket(tcp_listener.into_raw_socket()) }
@ -367,6 +369,7 @@ impl AsSocket for crate::net::UdpSocket {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::net::UdpSocket> for OwnedSocket {
/// Takes ownership of a [`UdpSocket`](crate::net::UdpSocket)'s underlying socket.
#[inline]
fn from(udp_socket: crate::net::UdpSocket) -> OwnedSocket {
unsafe { OwnedSocket::from_raw_socket(udp_socket.into_raw_socket()) }

View File

@ -24,6 +24,8 @@ impl FromRawHandle for process::Stdio {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<OwnedHandle> for process::Stdio {
/// Takes ownership of a handle and returns a [`Stdio`](process::Stdio)
/// that can attach a stream to it.
fn from(handle: OwnedHandle) -> process::Stdio {
let handle = sys::handle::Handle::from_inner(handle);
let io = sys::process::Stdio::Handle(handle);
@ -56,6 +58,7 @@ impl IntoRawHandle for process::Child {
#[stable(feature = "io_safety", since = "1.63.0")]
impl From<process::Child> for OwnedHandle {
/// Takes ownership of a [`Child`](process::Child)'s process handle.
fn from(child: process::Child) -> OwnedHandle {
child.into_inner().into_handle().into_inner()
}