Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize Bufwriter::into_raw_parts #84770

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions library/std/src/io/buffered/bufwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ impl<W: Write> BufWriter<W> {
/// # Examples
///
/// ```
/// #![feature(bufwriter_into_raw_parts)]
/// use std::io::{BufWriter, Write};
///
/// let mut buffer = [0u8; 10];
Expand All @@ -325,22 +324,21 @@ impl<W: Write> BufWriter<W> {
/// assert_eq!(recovered_writer.len(), 0);
/// assert_eq!(&buffered_data.unwrap(), b"ata");
/// ```
#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")]
#[stable(feature = "bufwriter_into_raw_parts", since = "1.53.0")]
pub fn into_raw_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 }) };
(self.inner.take().unwrap(), buf)
}
}

#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")]
#[stable(feature = "bufwriter_into_raw_parts", since = "1.53.0")]
/// Error returned for the buffered data from `BufWriter::into_raw_parts`, when the underlying
/// writer has previously panicked. Contains the (possibly partly written) buffered data.
///
/// # Example
///
/// ```
/// #![feature(bufwriter_into_raw_parts)]
/// use std::io::{self, BufWriter, Write};
/// use std::panic::{catch_unwind, AssertUnwindSafe};
///
Expand All @@ -367,7 +365,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")]
#[stable(feature = "bufwriter_into_raw_parts", since = "1.53.0")]
pub fn into_inner(self) -> Vec<u8> {
self.buf
}
Expand All @@ -376,22 +374,22 @@ impl WriterPanicked {
"BufWriter inner writer panicked, what data remains unwritten is not known";
}

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

#[unstable(feature = "bufwriter_into_raw_parts", issue = "80690")]
#[stable(feature = "bufwriter_into_raw_parts", since = "1.53.0")]
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")]
#[stable(feature = "bufwriter_into_raw_parts", since = "1.53.0")]
impl fmt::Debug for WriterPanicked {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("WriterPanicked")
Expand Down
6 changes: 2 additions & 4 deletions library/std/src/io/buffered/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ impl<W> IntoInnerError<W> {
///
/// # Example
/// ```
/// #![feature(io_into_inner_error_parts)]
/// use std::io::{BufWriter, ErrorKind, Write};
///
/// let mut not_enough_space = [0u8; 10];
Expand All @@ -143,7 +142,7 @@ impl<W> IntoInnerError<W> {
/// let err = into_inner_err.into_error();
/// assert_eq!(err.kind(), ErrorKind::WriteZero);
/// ```
#[unstable(feature = "io_into_inner_error_parts", issue = "79704")]
#[stable(feature = "io_into_inner_error_parts", since = "1.53.0")]
pub fn into_error(self) -> Error {
self.1
}
Expand All @@ -156,7 +155,6 @@ impl<W> IntoInnerError<W> {
///
/// # Example
/// ```
/// #![feature(io_into_inner_error_parts)]
/// use std::io::{BufWriter, ErrorKind, Write};
///
/// let mut not_enough_space = [0u8; 10];
Expand All @@ -167,7 +165,7 @@ impl<W> IntoInnerError<W> {
/// assert_eq!(err.kind(), ErrorKind::WriteZero);
/// assert_eq!(recovered_writer.buffer(), b"t be actually written");
/// ```
#[unstable(feature = "io_into_inner_error_parts", issue = "79704")]
#[stable(feature = "io_into_inner_error_parts", since = "1.53.0")]
pub fn into_parts(self) -> (Error, W) {
(self.1, self.0)
}
Expand Down