Struct WriterPanicked

struct WriterPanicked { ... }

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

use std::io::{self, BufWriter, Write};
use std::panic::{catch_unwind, AssertUnwindSafe};

struct PanickingWriter;
impl Write for PanickingWriter {
  fn write(&mut self, buf: &[u8]) -> io::Result<usize> { panic!() }
  fn flush(&mut self) -> io::Result<()> { panic!() }
}

let mut stream = BufWriter::new(PanickingWriter);
write!(stream, "some data").unwrap();
let result = catch_unwind(AssertUnwindSafe(|| {
    stream.flush().unwrap()
}));
assert!(result.is_err());
let (recovered_writer, buffered_data) = stream.into_parts();
assert!(matches!(recovered_writer, PanickingWriter));
assert_eq!(buffered_data.unwrap_err().into_inner(), b"some data");

Implementations

impl WriterPanicked

fn into_inner(self: Self) -> Vec<u8>

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.

impl Debug for WriterPanicked

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Display for WriterPanicked

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Error for WriterPanicked

impl Freeze for WriterPanicked

impl RefUnwindSafe for WriterPanicked

impl Send for WriterPanicked

impl Sync for WriterPanicked

impl Unpin for WriterPanicked

impl UnsafeUnpin for WriterPanicked

impl UnwindSafe for WriterPanicked

impl<T> Any for WriterPanicked

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for WriterPanicked

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for WriterPanicked

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> From for WriterPanicked

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToString for WriterPanicked

fn to_string(self: &Self) -> String

impl<T, U> Into for WriterPanicked

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for WriterPanicked

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for WriterPanicked

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>