Skip to content

Commit

Permalink
Rollup merge of rust-lang#85901 - ijackson:bufwriter-tweaks, r=joshtr…
Browse files Browse the repository at this point in the history
…iplett

Bufwriter disassembly tweaks

In rust-lang#80690 `@BurntSushi` observed that `WriterPanicked` was erroneously not exported, and suggested renaming `into_raw_parts` to `into_parts`. (More info in my commit messages.)

r? `@BurntSushi`
  • Loading branch information
JohnTitor committed Jul 28, 2021
2 parents efa3a2f + 51d16ac commit af62d11
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
26 changes: 13 additions & 13 deletions library/std/src/io/buffered/bufwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,24 +318,24 @@ impl<W: Write> BufWriter<W> {
/// In this case, we return `WriterPanicked` for the buffered data (from which the buffer
/// contents can still be recovered).
///
/// `into_raw_parts` makes no attempt to flush data and cannot fail.
/// `into_parts` makes no attempt to flush data and cannot fail.
///
/// # Examples
///
/// ```
/// #![feature(bufwriter_into_raw_parts)]
/// #![feature(bufwriter_into_parts)]
/// use std::io::{BufWriter, Write};
///
/// let mut buffer = [0u8; 10];
/// let mut stream = BufWriter::new(buffer.as_mut());
/// write!(stream, "too much data").unwrap();
/// stream.flush().expect_err("it doesn't fit");
/// let (recovered_writer, buffered_data) = stream.into_raw_parts();
/// let (recovered_writer, buffered_data) = stream.into_parts();
/// assert_eq!(recovered_writer.len(), 0);
/// assert_eq!(&buffered_data.unwrap(), b"ata");
/// ```
#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")]
pub fn into_raw_parts(mut self) -> (W, Result<Vec<u8>, WriterPanicked>) {
#[unstable(feature = "bufwriter_into_parts", issue = "80690")]
pub fn into_parts(mut self) -> (W, Result<Vec<u8>, WriterPanicked>) {
let buf = mem::take(&mut self.buf);
let buf = if !self.panicked { Ok(buf) } else { Err(WriterPanicked { buf }) };

Expand Down Expand Up @@ -444,14 +444,14 @@ impl<W: Write> BufWriter<W> {
}
}

#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")]
/// Error returned for the buffered data from `BufWriter::into_raw_parts`, when the underlying
#[unstable(feature = "bufwriter_into_parts", issue = "80690")]
/// Error returned for the buffered data from `BufWriter::into_parts`, when the underlying
/// writer has previously panicked. Contains the (possibly partly written) buffered data.
///
/// # Example
///
/// ```
/// #![feature(bufwriter_into_raw_parts)]
/// #![feature(bufwriter_into_parts)]
/// use std::io::{self, BufWriter, Write};
/// use std::panic::{catch_unwind, AssertUnwindSafe};
///
Expand All @@ -467,7 +467,7 @@ impl<W: Write> BufWriter<W> {
/// stream.flush().unwrap()
/// }));
/// assert!(result.is_err());
/// let (recovered_writer, buffered_data) = stream.into_raw_parts();
/// let (recovered_writer, buffered_data) = stream.into_parts();
/// assert!(matches!(recovered_writer, PanickingWriter));
/// assert_eq!(buffered_data.unwrap_err().into_inner(), b"some data");
/// ```
Expand All @@ -478,7 +478,7 @@ pub struct WriterPanicked {
impl WriterPanicked {
/// Returns the perhaps-unwritten data. Some of this data may have been written by the
/// panicking call(s) to the underlying writer, so simply writing it again is not a good idea.
#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")]
#[unstable(feature = "bufwriter_into_parts", issue = "80690")]
pub fn into_inner(self) -> Vec<u8> {
self.buf
}
Expand All @@ -487,22 +487,22 @@ impl WriterPanicked {
"BufWriter inner writer panicked, what data remains unwritten is not known";
}

#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")]
#[unstable(feature = "bufwriter_into_parts", issue = "80690")]
impl error::Error for WriterPanicked {
#[allow(deprecated, deprecated_in_future)]
fn description(&self) -> &str {
Self::DESCRIPTION
}
}

#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")]
#[unstable(feature = "bufwriter_into_parts", issue = "80690")]
impl fmt::Display for WriterPanicked {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", Self::DESCRIPTION)
}
}

#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")]
#[unstable(feature = "bufwriter_into_parts", issue = "80690")]
impl fmt::Debug for WriterPanicked {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("WriterPanicked")
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/io/buffered/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use crate::io::Error;

pub use bufreader::BufReader;
pub use bufwriter::BufWriter;
#[unstable(feature = "bufwriter_into_parts", issue = "80690")]
pub use bufwriter::WriterPanicked;
pub use linewriter::LineWriter;
use linewritershim::LineWriterShim;

Expand Down
2 changes: 2 additions & 0 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ use crate::sys_common::memchr;

#[stable(feature = "rust1", since = "1.0.0")]
pub use self::buffered::IntoInnerError;
#[unstable(feature = "bufwriter_into_parts", issue = "80690")]
pub use self::buffered::WriterPanicked;
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::buffered::{BufReader, BufWriter, LineWriter};
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down

0 comments on commit af62d11

Please sign in to comment.