Skip to content

Commit 78551dd

Browse files
committed
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
1 parent eb7b49a commit 78551dd

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/buffer.rs

+15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ impl<R: Read> BufReader<R> {
1717
BufReader::with_capacity(rdr, INIT_BUFFER_SIZE)
1818
}
1919

20+
#[inline]
21+
pub fn from_parts(rdr: R, buf: Vec<u8>, pos: usize, cap: usize) -> BufReader<R> {
22+
BufReader {
23+
inner: rdr,
24+
buf: buf,
25+
pos: pos,
26+
cap: cap,
27+
}
28+
}
29+
2030
#[inline]
2131
pub fn with_capacity(rdr: R, cap: usize) -> BufReader<R> {
2232
BufReader {
@@ -65,6 +75,11 @@ impl<R: Read> BufReader<R> {
6575
#[inline]
6676
pub fn into_inner(self) -> R { self.inner }
6777

78+
#[inline]
79+
pub fn into_parts(self) -> (R, Vec<u8>, usize, usize) {
80+
(self.inner, self.buf, self.pos, self.cap)
81+
}
82+
6883
#[inline]
6984
pub fn read_into_buf(&mut self) -> io::Result<usize> {
7085
self.maybe_reserve();

0 commit comments

Comments
 (0)