From 30caede6f8f5c777370014b67e4de5e50b24b777 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Wed, 29 Jan 2020 15:22:54 +0100 Subject: buffered-reader: New method BufferedReader::as_boxed. - This method returns the reader in a box. The nice thing is that we can provide a specialized implementation for Box that avoids boxing the reader twice. This cleanly addresses the issue worked around in 9619dffaa756d8cfd6ec691699bd6ae4d59ecfb5. --- buffered-reader/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'buffered-reader/src/lib.rs') diff --git a/buffered-reader/src/lib.rs b/buffered-reader/src/lib.rs index f226198e..4661b959 100644 --- a/buffered-reader/src/lib.rs +++ b/buffered-reader/src/lib.rs @@ -818,6 +818,13 @@ pub trait BufferedReader : io::Read + fmt::Debug + fmt::Display { Ok(at_least_one_byte) } + /// Boxes the reader. + fn as_boxed<'a>(self) -> Box + 'a> + where Self: 'a + Sized + { + Box::new(self) + } + /// Returns the underlying reader, if any. /// /// To allow this to work with `BufferedReader` traits, it is @@ -963,6 +970,12 @@ impl <'a, C> BufferedReader for Box + 'a> { self.as_ref().get_ref() } + fn as_boxed<'b>(self) -> Box + 'b> + where Self: 'b + { + self + } + fn into_inner<'b>(self: Box) -> Option + 'b>> where Self: 'b { // Strip the outer box. -- cgit v1.2.3