1
1
use crate :: io;
2
2
use crate :: sys:: anonymous_pipe:: { AnonPipe , pipe as pipe_inner} ;
3
3
4
- /// Create an anonymous pipe that is close-on-exec and blocking .
4
+ /// Create an anonymous pipe.
5
5
///
6
6
/// # Behavior
7
7
///
@@ -22,6 +22,13 @@ use crate::sys::anonymous_pipe::{AnonPipe, pipe as pipe_inner};
22
22
/// interleaving.
23
23
/// * Portable applications cannot assume any atomicity of messages larger than a single byte.
24
24
///
25
+ /// # Platform-specific behavior
26
+ ///
27
+ /// This function currently corresponds to the `pipe` function on Unix and the
28
+ /// `CreatePipe` function on Windows.
29
+ ///
30
+ /// Note that this [may change in the future][changes].
31
+ ///
25
32
/// # Capacity
26
33
///
27
34
/// Pipe capacity is platform dependent. To quote the Linux [man page]:
@@ -37,10 +44,10 @@ use crate::sys::anonymous_pipe::{AnonPipe, pipe as pipe_inner};
37
44
/// # #[cfg(miri)] fn main() {}
38
45
/// # #[cfg(not(miri))]
39
46
/// # fn main() -> std::io::Result<()> {
40
- /// # use std::process::Command;
41
- /// # use std::io::{Read, Write};
42
- /// let (ping_rx, mut ping_tx) = std::io:: pipe()?;
43
- /// let (mut pong_rx, pong_tx) = std::io:: pipe()?;
47
+ /// use std::process::Command;
48
+ /// use std::io::{pipe, Read, Write};
49
+ /// let (ping_rx, mut ping_tx) = pipe()?;
50
+ /// let (mut pong_rx, pong_tx) = pipe()?;
44
51
///
45
52
/// // Spawn a process that echoes its input.
46
53
/// let mut echo_server = Command::new("cat").stdin(ping_rx).stdout(pong_tx).spawn()?;
@@ -58,6 +65,7 @@ use crate::sys::anonymous_pipe::{AnonPipe, pipe as pipe_inner};
58
65
/// # Ok(())
59
66
/// # }
60
67
/// ```
68
+ /// [changes]: io#platform-specific-behavior
61
69
/// [man page]: https://man7.org/linux/man-pages/man7/pipe.7.html
62
70
#[ unstable( feature = "anonymous_pipe" , issue = "127154" ) ]
63
71
#[ inline]
@@ -85,15 +93,15 @@ impl PipeReader {
85
93
/// # #[cfg(miri)] fn main() {}
86
94
/// # #[cfg(not(miri))]
87
95
/// # fn main() -> std::io::Result<()> {
88
- /// # use std::fs;
89
- /// # use std::io::Write;
90
- /// # use std::process::Command;
96
+ /// use std::fs;
97
+ /// use std::io::{pipe, Write} ;
98
+ /// use std::process::Command;
91
99
/// const NUM_SLOT: u8 = 2;
92
100
/// const NUM_PROC: u8 = 5;
93
101
/// const OUTPUT: &str = "work.txt";
94
102
///
95
103
/// let mut jobs = vec![];
96
- /// let (reader, mut writer) = std::io:: pipe()?;
104
+ /// let (reader, mut writer) = pipe()?;
97
105
///
98
106
/// // Write NUM_SLOT characters the pipe.
99
107
/// writer.write_all(&[b'|'; NUM_SLOT as usize])?;
@@ -145,9 +153,9 @@ impl PipeWriter {
145
153
/// # #[cfg(miri)] fn main() {}
146
154
/// # #[cfg(not(miri))]
147
155
/// # fn main() -> std::io::Result<()> {
148
- /// # use std::process::Command;
149
- /// # use std::io::Read;
150
- /// let (mut reader, writer) = std::io:: pipe()?;
156
+ /// use std::process::Command;
157
+ /// use std::io::{pipe, Read} ;
158
+ /// let (mut reader, writer) = pipe()?;
151
159
///
152
160
/// // Spawn a process that writes to stdout and stderr.
153
161
/// let mut peer = Command::new("bash")
@@ -224,11 +232,9 @@ impl io::Write for &PipeWriter {
224
232
fn flush ( & mut self ) -> io:: Result < ( ) > {
225
233
Ok ( ( ) )
226
234
}
227
-
228
235
fn write_vectored ( & mut self , bufs : & [ io:: IoSlice < ' _ > ] ) -> io:: Result < usize > {
229
236
self . 0 . write_vectored ( bufs)
230
237
}
231
-
232
238
#[ inline]
233
239
fn is_write_vectored ( & self ) -> bool {
234
240
self . 0 . is_write_vectored ( )
@@ -244,11 +250,9 @@ impl io::Write for PipeWriter {
244
250
fn flush ( & mut self ) -> io:: Result < ( ) > {
245
251
Ok ( ( ) )
246
252
}
247
-
248
253
fn write_vectored ( & mut self , bufs : & [ io:: IoSlice < ' _ > ] ) -> io:: Result < usize > {
249
254
self . 0 . write_vectored ( bufs)
250
255
}
251
-
252
256
#[ inline]
253
257
fn is_write_vectored ( & self ) -> bool {
254
258
self . 0 . is_write_vectored ( )
0 commit comments