Provide two versions of drain_to and split_off

* `drain_to` and `split_off` take &self and return Bytes.
* `drain_to_mut` and `split_off_mut` take &mut self and return BytesMut
This commit is contained in:
Carl Lerche
2017-02-15 12:46:27 -08:00
parent 8da9e81469
commit 4c6ebeba87
3 changed files with 211 additions and 95 deletions
+2 -2
View File
@@ -75,14 +75,14 @@ impl ByteBuf {
/// Splits the buffer into two at the current read index.
pub fn drain_read(&mut self) -> BytesMut {
let drained = self.mem.drain_to(self.rd);
let drained = self.mem.drain_to_mut(self.rd);
self.rd = 0;
drained
}
/// Splits the buffer into two at the given index.
pub fn drain_to(&mut self, at: usize) -> BytesMut {
let drained = self.mem.drain_to(at);
let drained = self.mem.drain_to_mut(at);
if at >= self.rd {
self.rd = 0;