diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-01-25 23:15:23 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-25 23:15:23 +0100 |
| commit | 20d0f0187d2906af34bb747a79b93c14bb294df1 (patch) | |
| tree | 5b2536441b66dd526bab6921257c2d0262a4e4be | |
| parent | f01d418139e57790bb0f95651a466218ac178f33 (diff) | |
| parent | 687607c31e7397b958ccf3c9a8699977b5b183fe (diff) | |
| download | rust-20d0f0187d2906af34bb747a79b93c14bb294df1.tar.gz rust-20d0f0187d2906af34bb747a79b93c14bb294df1.zip | |
Rollup merge of #134373 - joshtriplett:pipe-docs, r=joboet
Improve and expand documentation of pipes - Reference UNIX, not just Linux - Simplify some of the language - Don't imply that pipes *only* work across multiple processes; instead, *suggest* that they're typically used across two or more separate processes. - Specify that portable applications cannot use multiple readers or multiple writers for messages larger than a byte, due to potential interleaving. Tracking issue for anonymous pipes: https://github.com/rust-lang/rust/issues/127154
| -rw-r--r-- | library/std/src/io/mod.rs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 231c8712ebd..1fa13e95e68 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -3252,18 +3252,26 @@ impl<B: BufRead> Iterator for Lines<B> { } } -/// Create anonymous pipe that is close-on-exec and blocking. +/// Create an anonymous pipe that is close-on-exec and blocking. /// /// # Behavior /// -/// A pipe is a synchronous, unidirectional data channel between two or more processes, like an -/// interprocess [`mpsc`](crate::sync::mpsc) provided by the OS. In particular: +/// A pipe is a one-way data channel provided by the OS, which works across processes. A pipe is +/// typically used to communicate between two or more separate processes, as there are better, +/// faster ways to communicate within a single process. +/// +/// In particular: /// /// * A read on a [`PipeReader`] blocks until the pipe is non-empty. /// * A write on a [`PipeWriter`] blocks when the pipe is full. /// * When all copies of a [`PipeWriter`] are closed, a read on the corresponding [`PipeReader`] /// returns EOF. -/// * [`PipeReader`] can be shared, but only one process will consume the data in the pipe. +/// * [`PipeWriter`] can be shared, and multiple processes or threads can write to it at once, but +/// writes (above a target-specific threshold) may have their data interleaved. +/// * [`PipeReader`] can be shared, and multiple processes or threads can read it at once. Any +/// given byte will only get consumed by one reader. There are no guarantees about data +/// interleaving. +/// * Portable applications cannot assume any atomicity of messages larger than a single byte. /// /// # Capacity /// @@ -3301,8 +3309,6 @@ impl<B: BufRead> Iterator for Lines<B> { /// # Ok(()) /// # } /// ``` -/// [pipe]: https://man7.org/linux/man-pages/man2/pipe.2.html -/// [CreatePipe]: https://learn.microsoft.com/en-us/windows/win32/api/namedpipeapi/nf-namedpipeapi-createpipe /// [man page]: https://man7.org/linux/man-pages/man7/pipe.7.html #[unstable(feature = "anonymous_pipe", issue = "127154")] #[inline] @@ -3310,12 +3316,12 @@ pub fn pipe() -> Result<(PipeReader, PipeWriter)> { pipe_inner().map(|(reader, writer)| (PipeReader(reader), PipeWriter(writer))) } -/// Read end of the anonymous pipe. +/// Read end of an anonymous pipe. #[unstable(feature = "anonymous_pipe", issue = "127154")] #[derive(Debug)] pub struct PipeReader(pub(crate) AnonPipe); -/// Write end of the anonymous pipe. +/// Write end of an anonymous pipe. #[unstable(feature = "anonymous_pipe", issue = "127154")] #[derive(Debug)] pub struct PipeWriter(pub(crate) AnonPipe); |
