mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 21:15:18 +03:00
Auto merge of #43459 - ids1024:asrawfd, r=alexcrichton
Implement AsRawFd for Stdin, Stdout, and Stderr https://github.com/rust-lang/rfcs/issues/2074
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
use fs;
|
||||
use net;
|
||||
use sys;
|
||||
use io;
|
||||
use sys_common::{self, AsInner, FromInner, IntoInner};
|
||||
|
||||
/// Raw file descriptors.
|
||||
@@ -109,6 +110,21 @@ fn as_raw_fd(&self) -> RawFd {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "asraw_stdio", since = "1.21.0")]
|
||||
impl AsRawFd for io::Stdin {
|
||||
fn as_raw_fd(&self) -> RawFd { 0 }
|
||||
}
|
||||
|
||||
#[stable(feature = "asraw_stdio", since = "1.21.0")]
|
||||
impl AsRawFd for io::Stdout {
|
||||
fn as_raw_fd(&self) -> RawFd { 1 }
|
||||
}
|
||||
|
||||
#[stable(feature = "asraw_stdio", since = "1.21.0")]
|
||||
impl AsRawFd for io::Stderr {
|
||||
fn as_raw_fd(&self) -> RawFd { 2 }
|
||||
}
|
||||
|
||||
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
||||
impl FromRawFd for net::TcpStream {
|
||||
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
use net;
|
||||
use os::raw;
|
||||
use sys;
|
||||
use io;
|
||||
use sys_common::{self, AsInner, FromInner, IntoInner};
|
||||
use libc;
|
||||
|
||||
/// Raw file descriptors.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@@ -104,6 +106,21 @@ impl AsRawFd for net::UdpSocket {
|
||||
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
|
||||
}
|
||||
|
||||
#[stable(feature = "asraw_stdio", since = "1.21.0")]
|
||||
impl AsRawFd for io::Stdin {
|
||||
fn as_raw_fd(&self) -> RawFd { libc::STDIN_FILENO }
|
||||
}
|
||||
|
||||
#[stable(feature = "asraw_stdio", since = "1.21.0")]
|
||||
impl AsRawFd for io::Stdout {
|
||||
fn as_raw_fd(&self) -> RawFd { libc::STDOUT_FILENO }
|
||||
}
|
||||
|
||||
#[stable(feature = "asraw_stdio", since = "1.21.0")]
|
||||
impl AsRawFd for io::Stderr {
|
||||
fn as_raw_fd(&self) -> RawFd { libc::STDERR_FILENO }
|
||||
}
|
||||
|
||||
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
||||
impl FromRawFd for net::TcpStream {
|
||||
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
use net;
|
||||
use sys_common::{self, AsInner, FromInner, IntoInner};
|
||||
use sys;
|
||||
use io;
|
||||
use sys::c;
|
||||
|
||||
/// Raw HANDLEs.
|
||||
@@ -71,6 +72,27 @@ fn as_raw_handle(&self) -> RawHandle {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "asraw_stdio", since = "1.21.0")]
|
||||
impl AsRawHandle for io::Stdin {
|
||||
fn as_raw_handle(&self) -> RawHandle {
|
||||
unsafe { c::GetStdHandle(c::STD_INPUT_HANDLE) as RawHandle }
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "asraw_stdio", since = "1.21.0")]
|
||||
impl AsRawHandle for io::Stdout {
|
||||
fn as_raw_handle(&self) -> RawHandle {
|
||||
unsafe { c::GetStdHandle(c::STD_OUTPUT_HANDLE) as RawHandle }
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "asraw_stdio", since = "1.21.0")]
|
||||
impl AsRawHandle for io::Stderr {
|
||||
fn as_raw_handle(&self) -> RawHandle {
|
||||
unsafe { c::GetStdHandle(c::STD_ERROR_HANDLE) as RawHandle }
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
||||
impl FromRawHandle for fs::File {
|
||||
unsafe fn from_raw_handle(handle: RawHandle) -> fs::File {
|
||||
|
||||
Reference in New Issue
Block a user