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:
commit
3a198077c9
@ -288,6 +288,7 @@ fn as_fd(&self) -> BorrowedFd<'_> {
|
||||
|
||||
#[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 @@ fn from(file: fs::File) -> 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 @@ fn as_fd(&self) -> BorrowedFd<'_> {
|
||||
|
||||
#[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 @@ fn as_fd(&self) -> BorrowedFd<'_> {
|
||||
|
||||
#[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 @@ fn as_fd(&self) -> BorrowedFd<'_> {
|
||||
|
||||
#[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()
|
||||
|
@ -1024,6 +1024,7 @@ fn as_fd(&self) -> BorrowedFd<'_> {
|
||||
|
||||
#[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()) }
|
||||
|
@ -346,6 +346,7 @@ fn from(fd: OwnedFd) -> 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()
|
||||
|
@ -752,6 +752,7 @@ fn as_fd(&self) -> BorrowedFd<'_> {
|
||||
|
||||
#[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()) }
|
||||
|
@ -362,6 +362,8 @@ unsafe fn from_raw_fd(fd: RawFd) -> 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 @@ fn as_fd(&self) -> BorrowedFd<'_> {
|
||||
|
||||
#[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 @@ fn as_fd(&self) -> BorrowedFd<'_> {
|
||||
|
||||
#[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 @@ fn as_fd(&self) -> BorrowedFd<'_> {
|
||||
|
||||
#[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()
|
||||
|
@ -502,6 +502,7 @@ fn as_handle(&self) -> BorrowedHandle<'_> {
|
||||
|
||||
#[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 @@ fn from(file: fs::File) -> 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 @@ fn as_handle(&self) -> BorrowedHandle<'_> {
|
||||
|
||||
#[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 @@ fn as_handle(&self) -> BorrowedHandle<'_> {
|
||||
|
||||
#[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 @@ fn as_handle(&self) -> BorrowedHandle<'_> {
|
||||
|
||||
#[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()) }
|
||||
|
@ -319,6 +319,7 @@ fn as_socket(&self) -> BorrowedSocket<'_> {
|
||||
|
||||
#[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 @@ fn as_socket(&self) -> BorrowedSocket<'_> {
|
||||
|
||||
#[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 @@ fn as_socket(&self) -> BorrowedSocket<'_> {
|
||||
|
||||
#[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()) }
|
||||
|
@ -24,6 +24,8 @@ unsafe fn from_raw_handle(handle: RawHandle) -> 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 @@ fn into_raw_handle(self) -> RawHandle {
|
||||
|
||||
#[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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user