From 5adb112a00b7854f16025a6f343796723c444fe1 Mon Sep 17 00:00:00 2001 From: yjhmelody <465402634@qq.com> Date: Wed, 13 Nov 2019 13:52:16 +0800 Subject: [PATCH] export IntoInnerError for io --- src/io/buf_writer.rs | 26 +++++++++++++++++++++++++- src/io/mod.rs | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/io/buf_writer.rs b/src/io/buf_writer.rs index 35b511f..ce6a97b 100644 --- a/src/io/buf_writer.rs +++ b/src/io/buf_writer.rs @@ -85,8 +85,32 @@ pin_project! { } } +/// An error returned by `into_inner` which combines an error that +/// happened while writing out the buffer, and the buffered writer object +/// which may be used to recover from the condition. +/// +/// # Examples +/// +/// ```no_run +/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// use async_std::io::BufWriter; +/// use async_std::net::TcpStream; +/// +/// let buf_writer = BufWriter::new(TcpStream::connect("127.0.0.1:34251").await?); +/// +/// // unwrap the TcpStream and flush the buffer +/// let stream = match buf_writer.into_inner().await { +/// Ok(s) => s, +/// Err(e) => { +/// // Here, e is an IntoInnerError +/// panic!("An error occurred"); +/// } +/// }; +/// # +/// # Ok(()) }) } +///``` #[derive(Debug)] -pub struct IntoInnerError(W, std::io::Error); +pub struct IntoInnerError(W, crate::io::Error); impl BufWriter { /// Creates a new `BufWriter` with a default buffer capacity. The default is currently 8 KB, diff --git a/src/io/mod.rs b/src/io/mod.rs index 065aaab..0c8144b 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -277,7 +277,7 @@ cfg_std! { pub use buf_read::{BufRead, Lines}; pub use buf_reader::BufReader; - pub use buf_writer::BufWriter; + pub use buf_writer::{BufWriter, IntoInnerError}; pub use copy::copy; pub use cursor::Cursor; pub use empty::{empty, Empty};