| @@ -27,7 +27,12 @@ impl<R: Read> BufReader<R> { | |||||||
|     pub fn get_mut(&mut self) -> &mut R { &mut self.inner } |     pub fn get_mut(&mut self) -> &mut R { &mut self.inner } | ||||||
|  |  | ||||||
|     pub fn get_buf(&self) -> &[u8] { |     pub fn get_buf(&self) -> &[u8] { | ||||||
|         self.buf.get_ref() |         let pos = self.buf.position() as usize; | ||||||
|  |         if pos < self.buf.get_ref().len() { | ||||||
|  |             &self.buf.get_ref()[pos..] | ||||||
|  |         } else { | ||||||
|  |             &[] | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     pub fn into_inner(self) -> R { self.inner } |     pub fn into_inner(self) -> R { self.inner } | ||||||
| @@ -93,3 +98,18 @@ fn reserve(v: &mut Vec<u8>) { | |||||||
|         v.reserve(cmp::min(cap * 4, MAX_BUFFER_SIZE) - cap); |         v.reserve(cmp::min(cap * 4, MAX_BUFFER_SIZE) - cap); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #[cfg(test)] | ||||||
|  | mod tests { | ||||||
|  |  | ||||||
|  |     use std::io::BufRead; | ||||||
|  |     use super::BufReader; | ||||||
|  |  | ||||||
|  |     #[test] | ||||||
|  |     fn test_consume_and_get_buf() { | ||||||
|  |         let mut rdr = BufReader::new(&b"foo bar baz"[..]); | ||||||
|  |         rdr.read_into_buf().unwrap(); | ||||||
|  |         rdr.consume(8); | ||||||
|  |         assert_eq!(rdr.get_buf(), b"baz"); | ||||||
|  |     } | ||||||
|  | } | ||||||
|   | |||||||
| @@ -228,7 +228,6 @@ mod tests { | |||||||
|             Host: example.domain\r\n\ |             Host: example.domain\r\n\ | ||||||
|             Expect: 100-continue\r\n\ |             Expect: 100-continue\r\n\ | ||||||
|             Content-Length: 10\r\n\ |             Content-Length: 10\r\n\ | ||||||
|             Connection: close\r\n\ |  | ||||||
|             \r\n\ |             \r\n\ | ||||||
|             1234567890\ |             1234567890\ | ||||||
|         "); |         "); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user