Struct std::io::WriterPanicked
1.56.0 · source · pub struct WriterPanicked { /* private fields */ }
Expand description
当底层 writer 之前有 panicked 时,为来自 BufWriter::into_parts
的缓冲数据返回错误。
包含 (可能是部分写入的) 缓冲数据。
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");
RunImplementations§
source§impl WriterPanicked
impl WriterPanicked
sourcepub fn into_inner(self) -> Vec<u8> ⓘ
pub fn into_inner(self) -> Vec<u8> ⓘ
返回可能未写入的数据。 其中一些数据可能是由 panic 调用写入底层编写器的,因此简单地再次编写它并不是一个好主意。
Trait Implementations§
source§impl Debug for WriterPanicked
impl Debug for WriterPanicked
source§impl Display for WriterPanicked
impl Display for WriterPanicked
Auto Trait Implementations§
impl RefUnwindSafe for WriterPanicked
impl Send for WriterPanicked
impl Sync for WriterPanicked
impl Unpin for WriterPanicked
impl UnwindSafe for WriterPanicked
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
从拥有的值中借用。 Read more