11use crate :: io;
22use crate :: sys:: anonymous_pipe:: { AnonPipe , pipe as pipe_inner} ;
33
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.
85///
96/// # Behavior
107///
@@ -17,6 +14,13 @@ use crate::sys::anonymous_pipe::{AnonPipe, pipe as pipe_inner};
1714/// returns EOF.
1815/// * [`PipeReader`] can be shared, but only one process will consume the data in the pipe.
1916///
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+ ///
2024/// # Capacity
2125///
2226/// 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};
3236/// # #[cfg(miri)] fn main() {}
3337/// # #[cfg(not(miri))]
3438/// # 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()?;
3943///
4044/// // Spawn a process that echoes its input.
4145/// 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};
5357/// # Ok(())
5458/// # }
5559/// ```
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
5861/// [man page]: https://man7.org/linux/man-pages/man7/pipe.7.html
5962#[ unstable( feature = "anonymous_pipe" , issue = "127154" ) ]
6063#[ inline]
@@ -82,15 +85,15 @@ impl PipeReader {
8285 /// # #[cfg(miri)] fn main() {}
8386 /// # #[cfg(not(miri))]
8487 /// # 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;
8891 /// const NUM_SLOT: u8 = 2;
8992 /// const NUM_PROC: u8 = 5;
9093 /// const OUTPUT: &str = "work.txt";
9194 ///
9295 /// let mut jobs = vec![];
93- /// let (reader, mut writer) = std::pipe:: pipe()?;
96+ /// let (reader, mut writer) = pipe()?;
9497 ///
9598 /// // Write NUM_SLOT characters the pipe.
9699 /// writer.write_all(&[b'|'; NUM_SLOT as usize])?;
@@ -142,9 +145,9 @@ impl PipeWriter {
142145 /// # #[cfg(miri)] fn main() {}
143146 /// # #[cfg(not(miri))]
144147 /// # 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()?;
148151 ///
149152 /// // Spawn a process that writes to stdout and stderr.
150153 /// let mut peer = Command::new("bash")
@@ -221,11 +224,9 @@ impl io::Write for &PipeWriter {
221224 fn flush ( & mut self ) -> io:: Result < ( ) > {
222225 Ok ( ( ) )
223226 }
224-
225227 fn write_vectored ( & mut self , bufs : & [ io:: IoSlice < ' _ > ] ) -> io:: Result < usize > {
226228 self . 0 . write_vectored ( bufs)
227229 }
228-
229230 #[ inline]
230231 fn is_write_vectored ( & self ) -> bool {
231232 self . 0 . is_write_vectored ( )
@@ -241,11 +242,9 @@ impl io::Write for PipeWriter {
241242 fn flush ( & mut self ) -> io:: Result < ( ) > {
242243 Ok ( ( ) )
243244 }
244-
245245 fn write_vectored ( & mut self , bufs : & [ io:: IoSlice < ' _ > ] ) -> io:: Result < usize > {
246246 self . 0 . write_vectored ( bufs)
247247 }
248-
249248 #[ inline]
250249 fn is_write_vectored ( & self ) -> bool {
251250 self . 0 . is_write_vectored ( )
0 commit comments