Document various I/O handle conversions

This commit is contained in:
Ryan Lowe 2024-02-04 12:14:53 -05:00
parent 6351247048
commit 5a74532aa1
8 changed files with 25 additions and 0 deletions

View File

@ -288,6 +288,7 @@ fn as_fd(&self) -> BorrowedFd<'_> {
#[stable(feature = "io_safety", since = "1.63.0")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<fs::File> for OwnedFd { impl From<fs::File> for OwnedFd {
/// Takes ownership of a [`File`](fs::File)'s underlying file descriptor.
#[inline] #[inline]
fn from(file: fs::File) -> OwnedFd { fn from(file: fs::File) -> OwnedFd {
file.into_inner().into_inner().into_inner() 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")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<OwnedFd> for fs::File { impl From<OwnedFd> for fs::File {
/// Returns a [`File`](fs::File) that takes ownership of the given
/// file descriptor.
#[inline] #[inline]
fn from(owned_fd: OwnedFd) -> Self { fn from(owned_fd: OwnedFd) -> Self {
Self::from_inner(FromInner::from_inner(FromInner::from_inner(owned_fd))) 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")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::net::TcpStream> for OwnedFd { impl From<crate::net::TcpStream> for OwnedFd {
/// Takes ownership of a [`TcpStream`](crate::net::TcpStream)'s socket file descriptor.
#[inline] #[inline]
fn from(tcp_stream: crate::net::TcpStream) -> OwnedFd { fn from(tcp_stream: crate::net::TcpStream) -> OwnedFd {
tcp_stream.into_inner().into_socket().into_inner().into_inner().into() 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")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::net::TcpListener> for OwnedFd { impl From<crate::net::TcpListener> for OwnedFd {
/// Takes ownership of a [`TcpListener`](crate::net::TcpListener)'s socket file descriptor.
#[inline] #[inline]
fn from(tcp_listener: crate::net::TcpListener) -> OwnedFd { fn from(tcp_listener: crate::net::TcpListener) -> OwnedFd {
tcp_listener.into_inner().into_socket().into_inner().into_inner().into() 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")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::net::UdpSocket> for OwnedFd { impl From<crate::net::UdpSocket> for OwnedFd {
/// Takes ownership of a [`UdpSocket`](crate::net::UdpSocket)'s file descriptor.
#[inline] #[inline]
fn from(udp_socket: crate::net::UdpSocket) -> OwnedFd { fn from(udp_socket: crate::net::UdpSocket) -> OwnedFd {
udp_socket.into_inner().into_socket().into_inner().into_inner().into() udp_socket.into_inner().into_socket().into_inner().into_inner().into()

View File

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

View File

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

View File

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

View File

@ -362,6 +362,8 @@ unsafe fn from_raw_fd(fd: RawFd) -> process::Stdio {
#[stable(feature = "io_safety", since = "1.63.0")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<OwnedFd> for process::Stdio { 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] #[inline]
fn from(fd: OwnedFd) -> process::Stdio { fn from(fd: OwnedFd) -> process::Stdio {
let fd = sys::fd::FileDesc::from_inner(fd); 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")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::process::ChildStdin> for OwnedFd { impl From<crate::process::ChildStdin> for OwnedFd {
/// Takes ownership of a [`ChildStdin`](crate::process::ChildStdin)'s file descriptor.
#[inline] #[inline]
fn from(child_stdin: crate::process::ChildStdin) -> OwnedFd { fn from(child_stdin: crate::process::ChildStdin) -> OwnedFd {
child_stdin.into_inner().into_inner().into_inner() 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")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::process::ChildStdout> for OwnedFd { impl From<crate::process::ChildStdout> for OwnedFd {
/// Takes ownership of a [`ChildStdout`](crate::process::ChildStdout)'s file descriptor.
#[inline] #[inline]
fn from(child_stdout: crate::process::ChildStdout) -> OwnedFd { fn from(child_stdout: crate::process::ChildStdout) -> OwnedFd {
child_stdout.into_inner().into_inner().into_inner() 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")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::process::ChildStderr> for OwnedFd { impl From<crate::process::ChildStderr> for OwnedFd {
/// Takes ownership of a [`ChildStderr`](crate::process::ChildStderr)'s file descriptor.
#[inline] #[inline]
fn from(child_stderr: crate::process::ChildStderr) -> OwnedFd { fn from(child_stderr: crate::process::ChildStderr) -> OwnedFd {
child_stderr.into_inner().into_inner().into_inner() child_stderr.into_inner().into_inner().into_inner()

View File

@ -502,6 +502,7 @@ fn as_handle(&self) -> BorrowedHandle<'_> {
#[stable(feature = "io_safety", since = "1.63.0")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<fs::File> for OwnedHandle { impl From<fs::File> for OwnedHandle {
/// Takes ownership of a [`File`](fs::File)'s underlying file handle.
#[inline] #[inline]
fn from(file: fs::File) -> OwnedHandle { fn from(file: fs::File) -> OwnedHandle {
file.into_inner().into_inner().into_inner() 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")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<OwnedHandle> for fs::File { impl From<OwnedHandle> for fs::File {
/// Returns a [`File`](fs::File) that takes ownership of the given handle.
#[inline] #[inline]
fn from(owned: OwnedHandle) -> Self { fn from(owned: OwnedHandle) -> Self {
Self::from_inner(FromInner::from_inner(FromInner::from_inner(owned))) 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")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::process::ChildStdin> for OwnedHandle { impl From<crate::process::ChildStdin> for OwnedHandle {
/// Takes ownership of a [`ChildStdin`](crate::process::ChildStdin)'s file handle.
#[inline] #[inline]
fn from(child_stdin: crate::process::ChildStdin) -> OwnedHandle { fn from(child_stdin: crate::process::ChildStdin) -> OwnedHandle {
unsafe { OwnedHandle::from_raw_handle(child_stdin.into_raw_handle()) } 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")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::process::ChildStdout> for OwnedHandle { impl From<crate::process::ChildStdout> for OwnedHandle {
/// Takes ownership of a [`ChildStdout`](crate::process::ChildStdout)'s file handle.
#[inline] #[inline]
fn from(child_stdout: crate::process::ChildStdout) -> OwnedHandle { fn from(child_stdout: crate::process::ChildStdout) -> OwnedHandle {
unsafe { OwnedHandle::from_raw_handle(child_stdout.into_raw_handle()) } 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")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::process::ChildStderr> for OwnedHandle { impl From<crate::process::ChildStderr> for OwnedHandle {
/// Takes ownership of a [`ChildStderr`](crate::process::ChildStderr)'s file handle.
#[inline] #[inline]
fn from(child_stderr: crate::process::ChildStderr) -> OwnedHandle { fn from(child_stderr: crate::process::ChildStderr) -> OwnedHandle {
unsafe { OwnedHandle::from_raw_handle(child_stderr.into_raw_handle()) } unsafe { OwnedHandle::from_raw_handle(child_stderr.into_raw_handle()) }

View File

@ -319,6 +319,7 @@ fn as_socket(&self) -> BorrowedSocket<'_> {
#[stable(feature = "io_safety", since = "1.63.0")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::net::TcpStream> for OwnedSocket { impl From<crate::net::TcpStream> for OwnedSocket {
/// Takes ownership of a [`TcpStream`](crate::net::TcpStream)'s socket.
#[inline] #[inline]
fn from(tcp_stream: crate::net::TcpStream) -> OwnedSocket { fn from(tcp_stream: crate::net::TcpStream) -> OwnedSocket {
unsafe { OwnedSocket::from_raw_socket(tcp_stream.into_raw_socket()) } 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")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::net::TcpListener> for OwnedSocket { impl From<crate::net::TcpListener> for OwnedSocket {
/// Takes ownership of a [`TcpListener`](crate::net::TcpListener)'s socket.
#[inline] #[inline]
fn from(tcp_listener: crate::net::TcpListener) -> OwnedSocket { fn from(tcp_listener: crate::net::TcpListener) -> OwnedSocket {
unsafe { OwnedSocket::from_raw_socket(tcp_listener.into_raw_socket()) } 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")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<crate::net::UdpSocket> for OwnedSocket { impl From<crate::net::UdpSocket> for OwnedSocket {
/// Takes ownership of a [`UdpSocket`](crate::net::UdpSocket)'s underlying socket.
#[inline] #[inline]
fn from(udp_socket: crate::net::UdpSocket) -> OwnedSocket { fn from(udp_socket: crate::net::UdpSocket) -> OwnedSocket {
unsafe { OwnedSocket::from_raw_socket(udp_socket.into_raw_socket()) } unsafe { OwnedSocket::from_raw_socket(udp_socket.into_raw_socket()) }

View File

@ -24,6 +24,8 @@ unsafe fn from_raw_handle(handle: RawHandle) -> process::Stdio {
#[stable(feature = "io_safety", since = "1.63.0")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<OwnedHandle> for process::Stdio { 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 { fn from(handle: OwnedHandle) -> process::Stdio {
let handle = sys::handle::Handle::from_inner(handle); let handle = sys::handle::Handle::from_inner(handle);
let io = sys::process::Stdio::Handle(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")] #[stable(feature = "io_safety", since = "1.63.0")]
impl From<process::Child> for OwnedHandle { impl From<process::Child> for OwnedHandle {
/// Takes ownership of a [`Child`](process::Child)'s process handle.
fn from(child: process::Child) -> OwnedHandle { fn from(child: process::Child) -> OwnedHandle {
child.into_inner().into_handle().into_inner() child.into_inner().into_handle().into_inner()
} }