forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#127701 - jhpratt:rollup-n50bfva, r=jhpratt
Rollup of 7 pull requests Successful merges: - rust-lang#122300 (Add FileCheck annotations to mir-opt/dest-prop tests) - rust-lang#127153 (Initial implementation of anonymous_pipe API) - rust-lang#127434 (use "bootstrap" instead of "rustbuild" in comments and docs) - rust-lang#127477 (Clear `inner_attr_ranges` regularly.) - rust-lang#127659 (Use ManuallyDrop in BufWriter::into_parts) - rust-lang#127671 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 8)) - rust-lang#127677 (using correct tool mode for `run-make-support` crate) r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
67 changed files
with
581 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
//! Module for annoymous pipe | ||
//! | ||
//! ``` | ||
//! #![feature(anonymous_pipe)] | ||
//! # fn main() -> std::io::Result<()> { | ||
//! let (reader, writer) = std::pipe::pipe()?; | ||
//! # Ok(()) | ||
//! # } | ||
//! ``` | ||
|
||
use crate::{io, sys::pipe::AnonPipe}; | ||
|
||
/// Create annoymous pipe that is close-on-exec and blocking. | ||
#[unstable(feature = "anonymous_pipe", issue = "127154")] | ||
#[inline] | ||
pub fn pipe() -> io::Result<(PipeReader, PipeWriter)> { | ||
cfg_if::cfg_if! { | ||
if #[cfg(unix)] { | ||
unix::pipe() | ||
} else if #[cfg(windows)] { | ||
windows::pipe() | ||
} else { | ||
Err(io::Error::UNSUPPORTED_PLATFORM) | ||
} | ||
} | ||
} | ||
|
||
/// Read end of the annoymous pipe. | ||
#[unstable(feature = "anonymous_pipe", issue = "127154")] | ||
#[derive(Debug)] | ||
pub struct PipeReader(AnonPipe); | ||
|
||
/// Write end of the annoymous pipe. | ||
#[unstable(feature = "anonymous_pipe", issue = "127154")] | ||
#[derive(Debug)] | ||
pub struct PipeWriter(AnonPipe); | ||
|
||
impl PipeReader { | ||
/// Create a new [`PipeReader`] instance that shares the same underlying file description. | ||
#[unstable(feature = "anonymous_pipe", issue = "127154")] | ||
pub fn try_clone(&self) -> io::Result<Self> { | ||
self.0.try_clone().map(Self) | ||
} | ||
} | ||
|
||
impl PipeWriter { | ||
/// Create a new [`PipeWriter`] instance that shares the same underlying file description. | ||
#[unstable(feature = "anonymous_pipe", issue = "127154")] | ||
pub fn try_clone(&self) -> io::Result<Self> { | ||
self.0.try_clone().map(Self) | ||
} | ||
} | ||
|
||
#[unstable(feature = "anonymous_pipe", issue = "127154")] | ||
impl io::Read for &PipeReader { | ||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { | ||
self.0.read(buf) | ||
} | ||
fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> { | ||
self.0.read_vectored(bufs) | ||
} | ||
#[inline] | ||
fn is_read_vectored(&self) -> bool { | ||
self.0.is_read_vectored() | ||
} | ||
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> { | ||
self.0.read_to_end(buf) | ||
} | ||
fn read_buf(&mut self, buf: io::BorrowedCursor<'_>) -> io::Result<()> { | ||
self.0.read_buf(buf) | ||
} | ||
} | ||
|
||
#[unstable(feature = "anonymous_pipe", issue = "127154")] | ||
impl io::Read for PipeReader { | ||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { | ||
self.0.read(buf) | ||
} | ||
fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> { | ||
self.0.read_vectored(bufs) | ||
} | ||
#[inline] | ||
fn is_read_vectored(&self) -> bool { | ||
self.0.is_read_vectored() | ||
} | ||
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> { | ||
self.0.read_to_end(buf) | ||
} | ||
fn read_buf(&mut self, buf: io::BorrowedCursor<'_>) -> io::Result<()> { | ||
self.0.read_buf(buf) | ||
} | ||
} | ||
|
||
#[unstable(feature = "anonymous_pipe", issue = "127154")] | ||
impl io::Write for &PipeWriter { | ||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { | ||
self.0.write(buf) | ||
} | ||
#[inline] | ||
fn flush(&mut self) -> io::Result<()> { | ||
Ok(()) | ||
} | ||
|
||
fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> { | ||
self.0.write_vectored(bufs) | ||
} | ||
|
||
#[inline] | ||
fn is_write_vectored(&self) -> bool { | ||
self.0.is_write_vectored() | ||
} | ||
} | ||
|
||
#[unstable(feature = "anonymous_pipe", issue = "127154")] | ||
impl io::Write for PipeWriter { | ||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { | ||
self.0.write(buf) | ||
} | ||
#[inline] | ||
fn flush(&mut self) -> io::Result<()> { | ||
Ok(()) | ||
} | ||
|
||
fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> { | ||
self.0.write_vectored(bufs) | ||
} | ||
|
||
#[inline] | ||
fn is_write_vectored(&self) -> bool { | ||
self.0.is_write_vectored() | ||
} | ||
} | ||
|
||
#[cfg(unix)] | ||
mod unix; | ||
|
||
#[cfg(windows)] | ||
mod windows; | ||
|
||
#[cfg(test)] | ||
mod tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use super::*; | ||
use crate::io::{Read, Write}; | ||
|
||
#[test] | ||
fn pipe_creation_and_rw() { | ||
let (mut rx, mut tx) = pipe().unwrap(); | ||
tx.write_all(b"12345").unwrap(); | ||
drop(tx); | ||
|
||
let mut s = String::new(); | ||
rx.read_to_string(&mut s).unwrap(); | ||
assert_eq!(s, "12345"); | ||
} | ||
|
||
#[test] | ||
fn pipe_try_clone_and_rw() { | ||
let (mut rx, mut tx) = pipe().unwrap(); | ||
tx.try_clone().unwrap().write_all(b"12").unwrap(); | ||
tx.write_all(b"345").unwrap(); | ||
drop(tx); | ||
|
||
let mut s = String::new(); | ||
rx.try_clone().unwrap().take(3).read_to_string(&mut s).unwrap(); | ||
assert_eq!(s, "123"); | ||
|
||
s.clear(); | ||
rx.read_to_string(&mut s).unwrap(); | ||
assert_eq!(s, "45"); | ||
} |
Oops, something went wrong.