mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-14 00:00:13 +02:00
Add Buf::copy_to_bytes(len) (#439)
This method replaces `Buf::to_bytes()`, providing a method that copies a subset of the remaining buffer into a `Bytes` value. As this is strictly more flexible, `to_bytes()` is removed. Fixes: #129, #398
This commit is contained in:
+8
-2
@@ -548,8 +548,14 @@ impl Buf for Bytes {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_bytes(&mut self) -> crate::Bytes {
|
||||
core::mem::replace(self, Bytes::new())
|
||||
fn copy_to_bytes(&mut self, len: usize) -> crate::Bytes {
|
||||
if len == self.remaining() {
|
||||
core::mem::replace(self, Bytes::new())
|
||||
} else {
|
||||
let ret = self.slice(..len);
|
||||
self.advance(len);
|
||||
ret
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user