Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document various I/O descriptor/handle conversions #120459

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions library/std/src/os/fd/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)))
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions library/std/src/os/unix/net/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }
Expand Down
1 change: 1 addition & 0 deletions library/std/src/os/unix/net/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions library/std/src/os/unix/net/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }
Expand Down
5 changes: 5 additions & 0 deletions library/std/src/os/unix/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions library/std/src/os/windows/io/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)))
Expand Down Expand Up @@ -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()) }
Expand All @@ -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()) }
Expand All @@ -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()) }
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/os/windows/io/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }
Expand All @@ -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()) }
Expand All @@ -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()) }
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/os/windows/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
}
Expand Down
Loading