1
1
use crate :: io;
2
2
use crate :: sys:: anonymous_pipe:: { AnonPipe , pipe as pipe_inner} ;
3
3
4
- /// Create anonymous pipe that is close-on-exec and blocking.
5
- ///
6
- /// This function provides support for anonymous OS pipes, like [pipe] on Linux or [CreatePipe] on
7
- /// Windows.
4
+ /// Create an anonymous pipe.
8
5
///
9
6
/// # Behavior
10
7
///
@@ -17,6 +14,13 @@ use crate::sys::anonymous_pipe::{AnonPipe, pipe as pipe_inner};
17
14
/// returns EOF.
18
15
/// * [`PipeReader`] can be shared, but only one process will consume the data in the pipe.
19
16
///
17
+ /// # Platform-specific behavior
18
+ ///
19
+ /// This function currently corresponds to the `pipe` function on Unix and the
20
+ /// `CreatePipe` function on Windows.
21
+ ///
22
+ /// Note that this [may change in the future][changes].
23
+ ///
20
24
/// # Capacity
21
25
///
22
26
/// Pipe capacity is platform dependent. To quote the Linux [man page]:
@@ -32,10 +36,10 @@ use crate::sys::anonymous_pipe::{AnonPipe, pipe as pipe_inner};
32
36
/// # #[cfg(miri)] fn main() {}
33
37
/// # #[cfg(not(miri))]
34
38
/// # fn main() -> std::io::Result<()> {
35
- /// # use std::process::Command;
36
- /// # use std::io::{Read, Write};
37
- /// let (ping_rx, mut ping_tx) = std::pipe:: pipe()?;
38
- /// let (mut pong_rx, pong_tx) = std::pipe:: pipe()?;
39
+ /// use std::process::Command;
40
+ /// use std::io::{pipe, Read, Write};
41
+ /// let (ping_rx, mut ping_tx) = pipe()?;
42
+ /// let (mut pong_rx, pong_tx) = pipe()?;
39
43
///
40
44
/// // Spawn a process that echoes its input.
41
45
/// let mut echo_server = Command::new("cat").stdin(ping_rx).stdout(pong_tx).spawn()?;
@@ -53,8 +57,7 @@ use crate::sys::anonymous_pipe::{AnonPipe, pipe as pipe_inner};
53
57
/// # Ok(())
54
58
/// # }
55
59
/// ```
56
- /// [pipe]: https://man7.org/linux/man-pages/man2/pipe.2.html
57
- /// [CreatePipe]: https://learn.microsoft.com/en-us/windows/win32/api/namedpipeapi/nf-namedpipeapi-createpipe
60
+ /// [changes]: io#platform-specific-behavior
58
61
/// [man page]: https://man7.org/linux/man-pages/man7/pipe.7.html
59
62
#[ unstable( feature = "anonymous_pipe" , issue = "127154" ) ]
60
63
#[ inline]
@@ -82,15 +85,15 @@ impl PipeReader {
82
85
/// # #[cfg(miri)] fn main() {}
83
86
/// # #[cfg(not(miri))]
84
87
/// # fn main() -> std::io::Result<()> {
85
- /// # use std::fs;
86
- /// # use std::io::Write;
87
- /// # use std::process::Command;
88
+ /// use std::fs;
89
+ /// use std::io::{pipe, Write} ;
90
+ /// use std::process::Command;
88
91
/// const NUM_SLOT: u8 = 2;
89
92
/// const NUM_PROC: u8 = 5;
90
93
/// const OUTPUT: &str = "work.txt";
91
94
///
92
95
/// let mut jobs = vec![];
93
- /// let (reader, mut writer) = std::pipe:: pipe()?;
96
+ /// let (reader, mut writer) = pipe()?;
94
97
///
95
98
/// // Write NUM_SLOT characters the pipe.
96
99
/// writer.write_all(&[b'|'; NUM_SLOT as usize])?;
@@ -142,9 +145,9 @@ impl PipeWriter {
142
145
/// # #[cfg(miri)] fn main() {}
143
146
/// # #[cfg(not(miri))]
144
147
/// # fn main() -> std::io::Result<()> {
145
- /// # use std::process::Command;
146
- /// # use std::io::Read;
147
- /// let (mut reader, writer) = std::pipe:: pipe()?;
148
+ /// use std::process::Command;
149
+ /// use std::io::{pipe, Read} ;
150
+ /// let (mut reader, writer) = pipe()?;
148
151
///
149
152
/// // Spawn a process that writes to stdout and stderr.
150
153
/// let mut peer = Command::new("bash")
@@ -221,11 +224,9 @@ impl io::Write for &PipeWriter {
221
224
fn flush ( & mut self ) -> io:: Result < ( ) > {
222
225
Ok ( ( ) )
223
226
}
224
-
225
227
fn write_vectored ( & mut self , bufs : & [ io:: IoSlice < ' _ > ] ) -> io:: Result < usize > {
226
228
self . 0 . write_vectored ( bufs)
227
229
}
228
-
229
230
#[ inline]
230
231
fn is_write_vectored ( & self ) -> bool {
231
232
self . 0 . is_write_vectored ( )
@@ -241,11 +242,9 @@ impl io::Write for PipeWriter {
241
242
fn flush ( & mut self ) -> io:: Result < ( ) > {
242
243
Ok ( ( ) )
243
244
}
244
-
245
245
fn write_vectored ( & mut self , bufs : & [ io:: IoSlice < ' _ > ] ) -> io:: Result < usize > {
246
246
self . 0 . write_vectored ( bufs)
247
247
}
248
-
249
248
#[ inline]
250
249
fn is_write_vectored ( & self ) -> bool {
251
250
self . 0 . is_write_vectored ( )
0 commit comments