Remove IntoBuf/FromBuf (#288)

As consequence Buf::collect is removed as well, which is replaced with `Buf::into_bytes`. The advantage of `Buf::into_bytes` is that it can be optimized in cases where converting a `T: Buf` into a `Bytes` instance is efficient.
This commit is contained in:
Douman
2019-08-27 13:09:43 -07:00
committed by Carl Lerche
parent 79e4b2847f
commit b6cb346adf
16 changed files with 97 additions and 373 deletions
+5 -13
View File
@@ -1,4 +1,4 @@
use crate::{Buf, BufMut, IntoBuf};
use crate::{Buf, BufMut};
use crate::buf::IntoIter;
use crate::debug;
@@ -133,8 +133,8 @@ pub struct Bytes {
///
/// let mut buf = BytesMut::with_capacity(64);
///
/// buf.put(b'h');
/// buf.put(b'e');
/// buf.put_u8(b'h');
/// buf.put_u8(b'e');
/// buf.put("llo");
///
/// assert_eq!(&buf[..], b"hello");
@@ -842,7 +842,7 @@ impl Bytes {
/// # Examples
///
/// ```
/// use bytes::{Buf, IntoBuf, Bytes};
/// use bytes::{Buf, Bytes};
///
/// let buf = Bytes::from(&b"abc"[..]);
/// let mut iter = buf.iter();
@@ -943,7 +943,7 @@ impl FromIterator<u8> for BytesMut {
for i in iter {
out.reserve(1);
out.put(i);
out.put_u8(i);
}
out
@@ -1602,14 +1602,6 @@ impl BufMut for BytesMut {
}
}
impl<'a> IntoBuf for &'a BytesMut {
type Buf = &'a [u8];
fn into_buf(self) -> Self::Buf {
self.as_ref()
}
}
impl AsRef<[u8]> for BytesMut {
#[inline]
fn as_ref(&self) -> &[u8] {