From 78551dd040e2ab46e833af355c92fe87aa026244 Mon Sep 17 00:00:00 2001 From: Michael Eden Date: Thu, 30 Mar 2017 12:00:53 -0400 Subject: [PATCH] feat(buffer): add from_parts and into_parts functions this adds the ability to deconstruct a buffer into all of its parts and the ability to create a buffer from all of its parts, this lets users deconstruct the buffer, edit the reader, then build it back up again without losing any information --- src/buffer.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/buffer.rs b/src/buffer.rs index 7341359c41..4f8449f796 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -17,6 +17,16 @@ impl BufReader { BufReader::with_capacity(rdr, INIT_BUFFER_SIZE) } + #[inline] + pub fn from_parts(rdr: R, buf: Vec, pos: usize, cap: usize) -> BufReader { + BufReader { + inner: rdr, + buf: buf, + pos: pos, + cap: cap, + } + } + #[inline] pub fn with_capacity(rdr: R, cap: usize) -> BufReader { BufReader { @@ -65,6 +75,11 @@ impl BufReader { #[inline] pub fn into_inner(self) -> R { self.inner } + #[inline] + pub fn into_parts(self) -> (R, Vec, usize, usize) { + (self.inner, self.buf, self.pos, self.cap) + } + #[inline] pub fn read_into_buf(&mut self) -> io::Result { self.maybe_reserve();