Skip to content

Commit 78c3d99

Browse files
authored
Rollup merge of rust-lang#137793 - NobodyXu:stablise-annoymous-pipe, r=joshtriplett
Stablize anonymous pipe Since rust-lang#135822 is staled, I create this PR to stablise anonymous pipe Closes rust-lang#127154
2 parents 6a23502 + 4c842c0 commit 78c3d99

File tree

15 files changed

+249
-225
lines changed

15 files changed

+249
-225
lines changed

library/std/src/io/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ pub use self::error::RawOsError;
310310
pub use self::error::SimpleMessage;
311311
#[unstable(feature = "io_const_error", issue = "133448")]
312312
pub use self::error::const_error;
313-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
313+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
314314
pub use self::pipe::{PipeReader, PipeWriter, pipe};
315315
#[stable(feature = "is_terminal", since = "1.70.0")]
316316
pub use self::stdio::IsTerminal;

library/std/src/io/pipe.rs

+34-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::io;
22
use crate::sys::anonymous_pipe::{AnonPipe, pipe as pipe_inner};
3+
use crate::sys_common::{FromInner, IntoInner};
34

45
/// Create an anonymous pipe.
56
///
@@ -40,7 +41,6 @@ use crate::sys::anonymous_pipe::{AnonPipe, pipe as pipe_inner};
4041
/// # Examples
4142
///
4243
/// ```no_run
43-
/// #![feature(anonymous_pipe)]
4444
/// # #[cfg(miri)] fn main() {}
4545
/// # #[cfg(not(miri))]
4646
/// # fn main() -> std::io::Result<()> {
@@ -67,29 +67,52 @@ use crate::sys::anonymous_pipe::{AnonPipe, pipe as pipe_inner};
6767
/// ```
6868
/// [changes]: io#platform-specific-behavior
6969
/// [man page]: https://man7.org/linux/man-pages/man7/pipe.7.html
70-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
70+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
7171
#[inline]
7272
pub fn pipe() -> io::Result<(PipeReader, PipeWriter)> {
7373
pipe_inner().map(|(reader, writer)| (PipeReader(reader), PipeWriter(writer)))
7474
}
7575

7676
/// Read end of an anonymous pipe.
77-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
77+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
7878
#[derive(Debug)]
7979
pub struct PipeReader(pub(crate) AnonPipe);
8080

8181
/// Write end of an anonymous pipe.
82-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
82+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
8383
#[derive(Debug)]
8484
pub struct PipeWriter(pub(crate) AnonPipe);
8585

86+
impl FromInner<AnonPipe> for PipeReader {
87+
fn from_inner(inner: AnonPipe) -> Self {
88+
Self(inner)
89+
}
90+
}
91+
92+
impl IntoInner<AnonPipe> for PipeReader {
93+
fn into_inner(self) -> AnonPipe {
94+
self.0
95+
}
96+
}
97+
98+
impl FromInner<AnonPipe> for PipeWriter {
99+
fn from_inner(inner: AnonPipe) -> Self {
100+
Self(inner)
101+
}
102+
}
103+
104+
impl IntoInner<AnonPipe> for PipeWriter {
105+
fn into_inner(self) -> AnonPipe {
106+
self.0
107+
}
108+
}
109+
86110
impl PipeReader {
87111
/// Create a new [`PipeReader`] instance that shares the same underlying file description.
88112
///
89113
/// # Examples
90114
///
91115
/// ```no_run
92-
/// #![feature(anonymous_pipe)]
93116
/// # #[cfg(miri)] fn main() {}
94117
/// # #[cfg(not(miri))]
95118
/// # fn main() -> std::io::Result<()> {
@@ -137,7 +160,7 @@ impl PipeReader {
137160
/// # Ok(())
138161
/// # }
139162
/// ```
140-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
163+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
141164
pub fn try_clone(&self) -> io::Result<Self> {
142165
self.0.try_clone().map(Self)
143166
}
@@ -149,7 +172,6 @@ impl PipeWriter {
149172
/// # Examples
150173
///
151174
/// ```no_run
152-
/// #![feature(anonymous_pipe)]
153175
/// # #[cfg(miri)] fn main() {}
154176
/// # #[cfg(not(miri))]
155177
/// # fn main() -> std::io::Result<()> {
@@ -177,13 +199,13 @@ impl PipeWriter {
177199
/// # Ok(())
178200
/// # }
179201
/// ```
180-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
202+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
181203
pub fn try_clone(&self) -> io::Result<Self> {
182204
self.0.try_clone().map(Self)
183205
}
184206
}
185207

186-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
208+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
187209
impl io::Read for &PipeReader {
188210
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
189211
self.0.read(buf)
@@ -203,7 +225,7 @@ impl io::Read for &PipeReader {
203225
}
204226
}
205227

206-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
228+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
207229
impl io::Read for PipeReader {
208230
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
209231
self.0.read(buf)
@@ -223,7 +245,7 @@ impl io::Read for PipeReader {
223245
}
224246
}
225247

226-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
248+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
227249
impl io::Write for &PipeWriter {
228250
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
229251
self.0.write(buf)
@@ -241,7 +263,7 @@ impl io::Write for &PipeWriter {
241263
}
242264
}
243265

244-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
266+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
245267
impl io::Write for PipeWriter {
246268
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
247269
self.0.write(buf)

library/std/src/os/fd/owned.rs

+43-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use super::raw::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
77
use crate::marker::PhantomData;
88
use crate::mem::ManuallyDrop;
99
#[cfg(not(any(target_arch = "wasm32", target_env = "sgx", target_os = "hermit")))]
10-
use crate::sys::cvt;
10+
use crate::sys::{cvt, fd::FileDesc};
1111
use crate::sys_common::{AsInner, FromInner, IntoInner};
1212
use crate::{fmt, fs, io};
1313

@@ -484,3 +484,45 @@ impl<'a> AsFd for io::StderrLock<'a> {
484484
unsafe { BorrowedFd::borrow_raw(2) }
485485
}
486486
}
487+
488+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
489+
impl AsFd for io::PipeReader {
490+
fn as_fd(&self) -> BorrowedFd<'_> {
491+
self.0.as_fd()
492+
}
493+
}
494+
495+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
496+
impl From<io::PipeReader> for OwnedFd {
497+
fn from(pipe: io::PipeReader) -> Self {
498+
FileDesc::into_inner(pipe.0)
499+
}
500+
}
501+
502+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
503+
impl AsFd for io::PipeWriter {
504+
fn as_fd(&self) -> BorrowedFd<'_> {
505+
self.0.as_fd()
506+
}
507+
}
508+
509+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
510+
impl From<io::PipeWriter> for OwnedFd {
511+
fn from(pipe: io::PipeWriter) -> Self {
512+
FileDesc::into_inner(pipe.0)
513+
}
514+
}
515+
516+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
517+
impl From<OwnedFd> for io::PipeReader {
518+
fn from(owned_fd: OwnedFd) -> Self {
519+
Self(FileDesc::from_inner(owned_fd))
520+
}
521+
}
522+
523+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
524+
impl From<OwnedFd> for io::PipeWriter {
525+
fn from(owned_fd: OwnedFd) -> Self {
526+
Self(FileDesc::from_inner(owned_fd))
527+
}
528+
}

library/std/src/os/fd/raw.rs

+43
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::os::unix::io::AsFd;
1515
use crate::os::unix::io::OwnedFd;
1616
#[cfg(target_os = "wasi")]
1717
use crate::os::wasi::io::OwnedFd;
18+
use crate::sys::fd::FileDesc;
1819
use crate::sys_common::{AsInner, IntoInner};
1920
use crate::{fs, io};
2021

@@ -276,3 +277,45 @@ impl<T: AsRawFd> AsRawFd for Box<T> {
276277
(**self).as_raw_fd()
277278
}
278279
}
280+
281+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
282+
impl AsRawFd for io::PipeReader {
283+
fn as_raw_fd(&self) -> RawFd {
284+
self.0.as_raw_fd()
285+
}
286+
}
287+
288+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
289+
impl FromRawFd for io::PipeReader {
290+
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
291+
unsafe { Self(FileDesc::from_raw_fd(raw_fd)) }
292+
}
293+
}
294+
295+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
296+
impl IntoRawFd for io::PipeReader {
297+
fn into_raw_fd(self) -> RawFd {
298+
self.0.into_raw_fd()
299+
}
300+
}
301+
302+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
303+
impl AsRawFd for io::PipeWriter {
304+
fn as_raw_fd(&self) -> RawFd {
305+
self.0.as_raw_fd()
306+
}
307+
}
308+
309+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
310+
impl FromRawFd for io::PipeWriter {
311+
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
312+
unsafe { Self(FileDesc::from_raw_fd(raw_fd)) }
313+
}
314+
}
315+
316+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
317+
impl IntoRawFd for io::PipeWriter {
318+
fn into_raw_fd(self) -> RawFd {
319+
self.0.into_raw_fd()
320+
}
321+
}

library/std/src/os/windows/io/handle.rs

+42
Original file line numberDiff line numberDiff line change
@@ -660,3 +660,45 @@ impl<T> From<crate::thread::JoinHandle<T>> for OwnedHandle {
660660
join_handle.into_inner().into_handle().into_inner()
661661
}
662662
}
663+
664+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
665+
impl AsHandle for io::PipeReader {
666+
fn as_handle(&self) -> BorrowedHandle<'_> {
667+
self.0.as_handle()
668+
}
669+
}
670+
671+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
672+
impl From<io::PipeReader> for OwnedHandle {
673+
fn from(pipe: io::PipeReader) -> Self {
674+
pipe.into_inner().into_inner()
675+
}
676+
}
677+
678+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
679+
impl AsHandle for io::PipeWriter {
680+
fn as_handle(&self) -> BorrowedHandle<'_> {
681+
self.0.as_handle()
682+
}
683+
}
684+
685+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
686+
impl From<io::PipeWriter> for OwnedHandle {
687+
fn from(pipe: io::PipeWriter) -> Self {
688+
pipe.into_inner().into_inner()
689+
}
690+
}
691+
692+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
693+
impl From<OwnedHandle> for io::PipeReader {
694+
fn from(owned_handle: OwnedHandle) -> Self {
695+
Self::from_inner(FromInner::from_inner(owned_handle))
696+
}
697+
}
698+
699+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
700+
impl From<OwnedHandle> for io::PipeWriter {
701+
fn from(owned_handle: OwnedHandle) -> Self {
702+
Self::from_inner(FromInner::from_inner(owned_handle))
703+
}
704+
}

library/std/src/os/windows/io/raw.rs

+42
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,45 @@ impl IntoRawSocket for net::UdpSocket {
310310
self.into_inner().into_socket().into_inner().into_raw_socket()
311311
}
312312
}
313+
314+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
315+
impl AsRawHandle for io::PipeReader {
316+
fn as_raw_handle(&self) -> RawHandle {
317+
self.0.as_raw_handle()
318+
}
319+
}
320+
321+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
322+
impl FromRawHandle for io::PipeReader {
323+
unsafe fn from_raw_handle(raw_handle: RawHandle) -> Self {
324+
unsafe { Self::from_inner(FromRawHandle::from_raw_handle(raw_handle)) }
325+
}
326+
}
327+
328+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
329+
impl IntoRawHandle for io::PipeReader {
330+
fn into_raw_handle(self) -> RawHandle {
331+
self.0.into_raw_handle()
332+
}
333+
}
334+
335+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
336+
impl AsRawHandle for io::PipeWriter {
337+
fn as_raw_handle(&self) -> RawHandle {
338+
self.0.as_raw_handle()
339+
}
340+
}
341+
342+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
343+
impl FromRawHandle for io::PipeWriter {
344+
unsafe fn from_raw_handle(raw_handle: RawHandle) -> Self {
345+
unsafe { Self::from_inner(FromRawHandle::from_raw_handle(raw_handle)) }
346+
}
347+
}
348+
349+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
350+
impl IntoRawHandle for io::PipeWriter {
351+
fn into_raw_handle(self) -> RawHandle {
352+
self.0.into_raw_handle()
353+
}
354+
}

library/std/src/process.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,20 @@ impl From<io::Stderr> for Stdio {
16581658
}
16591659
}
16601660

1661+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
1662+
impl From<io::PipeWriter> for Stdio {
1663+
fn from(pipe: io::PipeWriter) -> Self {
1664+
Stdio::from_inner(pipe.into_inner().into())
1665+
}
1666+
}
1667+
1668+
#[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
1669+
impl From<io::PipeReader> for Stdio {
1670+
fn from(pipe: io::PipeReader) -> Self {
1671+
Stdio::from_inner(pipe.into_inner().into())
1672+
}
1673+
}
1674+
16611675
/// Describes the result of a process after it has terminated.
16621676
///
16631677
/// This `struct` is used to represent the exit status or other termination of a child process.

0 commit comments

Comments
 (0)