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:
Carl Lerche
2020-10-20 11:00:35 -07:00
committed by GitHub
parent 5866839e45
commit 39de065a1e
6 changed files with 48 additions and 17 deletions
+3 -3
View File
@@ -21,7 +21,7 @@ use std::io::IoSlice;
/// let mut buf = (&b"hello "[..])
/// .chain(&b"world"[..]);
///
/// let full: Bytes = buf.to_bytes();
/// let full: Bytes = buf.copy_to_bytes(11);
/// assert_eq!(full[..], b"hello world"[..]);
/// ```
///
@@ -68,7 +68,7 @@ impl<T, U> Chain<T, U> {
///
/// buf.first_mut().advance(1);
///
/// let full = buf.to_bytes();
/// let full = buf.copy_to_bytes(9);
/// assert_eq!(full, b"elloworld"[..]);
/// ```
pub fn first_mut(&mut self) -> &mut T {
@@ -103,7 +103,7 @@ impl<T, U> Chain<T, U> {
///
/// buf.last_mut().advance(1);
///
/// let full = buf.to_bytes();
/// let full = buf.copy_to_bytes(10);
/// assert_eq!(full, b"hello orld"[..]);
/// ```
pub fn last_mut(&mut self) -> &mut U {