Skip to content

Commit

Permalink
feat(buffer): add from_parts and into_parts functions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
illegalprime committed Mar 30, 2017
1 parent eb7b49a commit 78551dd
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ impl<R: Read> BufReader<R> {
BufReader::with_capacity(rdr, INIT_BUFFER_SIZE)
}

#[inline]
pub fn from_parts(rdr: R, buf: Vec<u8>, pos: usize, cap: usize) -> BufReader<R> {
BufReader {
inner: rdr,
buf: buf,
pos: pos,
cap: cap,
}
}

#[inline]
pub fn with_capacity(rdr: R, cap: usize) -> BufReader<R> {
BufReader {
Expand Down Expand Up @@ -65,6 +75,11 @@ impl<R: Read> BufReader<R> {
#[inline]
pub fn into_inner(self) -> R { self.inner }

#[inline]
pub fn into_parts(self) -> (R, Vec<u8>, usize, usize) {
(self.inner, self.buf, self.pos, self.cap)
}

#[inline]
pub fn read_into_buf(&mut self) -> io::Result<usize> {
self.maybe_reserve();
Expand Down

0 comments on commit 78551dd

Please sign in to comment.