@@ -304,6 +304,27 @@ pub struct BufWriter<W: Write> {
304304/// An error returned by `into_inner` which combines an error that
305305/// happened while writing out the buffer, and the buffered writer object
306306/// which may be used to recover from the condition.
307+ ///
308+ /// # Examples
309+ ///
310+ /// ```no_run
311+ /// use std::io::BufWriter;
312+ /// use std::net::TcpStream;
313+ ///
314+ /// let mut stream = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
315+ ///
316+ /// // do stuff with the stream
317+ ///
318+ /// // we want to get our `TcpStream` back, so let's try:
319+ ///
320+ /// let stream = match stream.into_inner() {
321+ /// Ok(s) => s,
322+ /// Err(e) => {
323+ /// // Here, e is an IntoInnerError
324+ /// panic!("An error occurred");
325+ /// }
326+ /// };
327+ /// ```
307328#[ derive( Debug ) ]
308329#[ stable( feature = "rust1" , since = "1.0.0" ) ]
309330pub struct IntoInnerError < W > ( W , Error ) ;
@@ -476,16 +497,67 @@ impl<W: Write> Drop for BufWriter<W> {
476497}
477498
478499impl < W > IntoInnerError < W > {
479- /// Returns the error which caused the call to `into_inner` to fail.
500+ /// Returns the error which caused the call to `into_inner() ` to fail.
480501 ///
481502 /// This error was returned when attempting to write the internal buffer.
503+ ///
504+ /// # Examples
505+ ///
506+ /// ```no_run
507+ /// use std::io::BufWriter;
508+ /// use std::net::TcpStream;
509+ ///
510+ /// let mut stream = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
511+ ///
512+ /// // do stuff with the stream
513+ ///
514+ /// // we want to get our `TcpStream` back, so let's try:
515+ ///
516+ /// let stream = match stream.into_inner() {
517+ /// Ok(s) => s,
518+ /// Err(e) => {
519+ /// // Here, e is an IntoInnerError, let's log the inner error.
520+ /// //
521+ /// // We'll just 'log' to stdout for this example.
522+ /// println!("{}", e.error());
523+ ///
524+ /// panic!("An unexpected error occurred.");
525+ /// }
526+ /// };
527+ /// ```
482528 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
483529 pub fn error ( & self ) -> & Error { & self . 1 }
484530
485531 /// Returns the buffered writer instance which generated the error.
486532 ///
487533 /// The returned object can be used for error recovery, such as
488534 /// re-inspecting the buffer.
535+ ///
536+ /// # Examples
537+ ///
538+ /// ```no_run
539+ /// use std::io::BufWriter;
540+ /// use std::net::TcpStream;
541+ ///
542+ /// let mut stream = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
543+ ///
544+ /// // do stuff with the stream
545+ ///
546+ /// // we want to get our `TcpStream` back, so let's try:
547+ ///
548+ /// let stream = match stream.into_inner() {
549+ /// Ok(s) => s,
550+ /// Err(e) => {
551+ /// // Here, e is a IntoInnerError, let's re-examine the buffer:
552+ /// let buffer = e.into_inner();
553+ ///
554+ /// // do stuff to try to recover
555+ ///
556+ /// // afterwards, let's just return the stream
557+ /// buffer.into_inner().unwrap()
558+ /// }
559+ /// };
560+ /// ```
489561 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
490562 pub fn into_inner ( self ) -> W { self . 0 }
491563}
0 commit comments