11use crate :: io;
22use crate :: sys:: anonymous_pipe:: { AnonPipe , pipe as pipe_inner} ;
33
4- /// Create an anonymous pipe that is close-on-exec and blocking .
4+ /// Create an anonymous pipe.
55///
66/// # Behavior
77///
@@ -22,6 +22,13 @@ use crate::sys::anonymous_pipe::{AnonPipe, pipe as pipe_inner};
2222/// interleaving.
2323/// * Portable applications cannot assume any atomicity of messages larger than a single byte.
2424///
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+ ///
2532/// # Capacity
2633///
2734/// 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};
3744/// # #[cfg(miri)] fn main() {}
3845/// # #[cfg(not(miri))]
3946/// # 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()?;
4451///
4552/// // Spawn a process that echoes its input.
4653/// 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};
5865/// # Ok(())
5966/// # }
6067/// ```
68+ /// [changes]: io#platform-specific-behavior
6169/// [man page]: https://man7.org/linux/man-pages/man7/pipe.7.html
6270#[ unstable( feature = "anonymous_pipe" , issue = "127154" ) ]
6371#[ inline]
@@ -85,15 +93,15 @@ impl PipeReader {
8593 /// # #[cfg(miri)] fn main() {}
8694 /// # #[cfg(not(miri))]
8795 /// # 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;
9199 /// const NUM_SLOT: u8 = 2;
92100 /// const NUM_PROC: u8 = 5;
93101 /// const OUTPUT: &str = "work.txt";
94102 ///
95103 /// let mut jobs = vec![];
96- /// let (reader, mut writer) = std::io:: pipe()?;
104+ /// let (reader, mut writer) = pipe()?;
97105 ///
98106 /// // Write NUM_SLOT characters the pipe.
99107 /// writer.write_all(&[b'|'; NUM_SLOT as usize])?;
@@ -145,9 +153,9 @@ impl PipeWriter {
145153 /// # #[cfg(miri)] fn main() {}
146154 /// # #[cfg(not(miri))]
147155 /// # 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()?;
151159 ///
152160 /// // Spawn a process that writes to stdout and stderr.
153161 /// let mut peer = Command::new("bash")
@@ -224,11 +232,9 @@ impl io::Write for &PipeWriter {
224232 fn flush ( & mut self ) -> io:: Result < ( ) > {
225233 Ok ( ( ) )
226234 }
227-
228235 fn write_vectored ( & mut self , bufs : & [ io:: IoSlice < ' _ > ] ) -> io:: Result < usize > {
229236 self . 0 . write_vectored ( bufs)
230237 }
231-
232238 #[ inline]
233239 fn is_write_vectored ( & self ) -> bool {
234240 self . 0 . is_write_vectored ( )
@@ -244,11 +250,9 @@ impl io::Write for PipeWriter {
244250 fn flush ( & mut self ) -> io:: Result < ( ) > {
245251 Ok ( ( ) )
246252 }
247-
248253 fn write_vectored ( & mut self , bufs : & [ io:: IoSlice < ' _ > ] ) -> io:: Result < usize > {
249254 self . 0 . write_vectored ( bufs)
250255 }
251-
252256 #[ inline]
253257 fn is_write_vectored ( & self ) -> bool {
254258 self . 0 . is_write_vectored ( )
0 commit comments