@@ -4,11 +4,9 @@ use std::pin::Pin;
44use pin_project_lite:: pin_project;
55
66use crate :: io:: write:: WriteExt ;
7- use crate :: io:: { self , Seek , SeekFrom , Write } ;
7+ use crate :: io:: { self , Seek , SeekFrom , Write , DEFAULT_BUF_SIZE } ;
88use crate :: task:: { Context , Poll , ready} ;
99
10- const DEFAULT_CAPACITY : usize = 8 * 1024 ;
11-
1210pin_project ! {
1311 /// Wraps a writer and buffers its output.
1412 ///
@@ -87,8 +85,32 @@ pin_project! {
8785 }
8886}
8987
88+ /// An error returned by `into_inner` which combines an error that
89+ /// happened while writing out the buffer, and the buffered writer object
90+ /// which may be used to recover from the condition.
91+ ///
92+ /// # Examples
93+ ///
94+ /// ```no_run
95+ /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
96+ /// use async_std::io::BufWriter;
97+ /// use async_std::net::TcpStream;
98+ ///
99+ /// let buf_writer = BufWriter::new(TcpStream::connect("127.0.0.1:34251").await?);
100+ ///
101+ /// // unwrap the TcpStream and flush the buffer
102+ /// let stream = match buf_writer.into_inner().await {
103+ /// Ok(s) => s,
104+ /// Err(e) => {
105+ /// // Here, e is an IntoInnerError
106+ /// panic!("An error occurred");
107+ /// }
108+ /// };
109+ /// #
110+ /// # Ok(()) }) }
111+ ///```
90112#[ derive( Debug ) ]
91- pub struct IntoInnerError < W > ( W , std :: io:: Error ) ;
113+ pub struct IntoInnerError < W > ( W , crate :: io:: Error ) ;
92114
93115impl < W : Write > BufWriter < W > {
94116 /// Creates a new `BufWriter` with a default buffer capacity. The default is currently 8 KB,
@@ -107,7 +129,7 @@ impl<W: Write> BufWriter<W> {
107129 /// # Ok(()) }) }
108130 /// ```
109131 pub fn new ( inner : W ) -> BufWriter < W > {
110- BufWriter :: with_capacity ( DEFAULT_CAPACITY , inner)
132+ BufWriter :: with_capacity ( DEFAULT_BUF_SIZE , inner)
111133 }
112134
113135 /// Creates a new `BufWriter` with the specified buffer capacity.
0 commit comments