Impl IntoBuf for Bytes and BytesMut

This commit is contained in:
Carl Lerche
2016-11-02 14:33:42 -07:00
parent 11fe277c0d
commit a367a723d8
+33 -1
View File
@@ -1,4 +1,4 @@
use ByteBuf;
use {IntoBuf, ByteBuf, SliceBuf};
use std::cell::UnsafeCell;
use std::sync::Arc;
@@ -130,6 +130,22 @@ impl Bytes {
}
}
impl IntoBuf for Bytes {
type Buf = SliceBuf<Self>;
fn into_buf(self) -> Self::Buf {
SliceBuf::new(self)
}
}
impl<'a> IntoBuf for &'a Bytes {
type Buf = SliceBuf<Self>;
fn into_buf(self) -> Self::Buf {
SliceBuf::new(self)
}
}
impl Clone for Bytes {
fn clone(&self) -> Bytes {
Bytes { inner: self.inner.clone() }
@@ -343,6 +359,22 @@ impl BytesMut {
}
}
impl IntoBuf for BytesMut {
type Buf = SliceBuf<Self>;
fn into_buf(self) -> Self::Buf {
SliceBuf::new(self)
}
}
impl<'a> IntoBuf for &'a BytesMut {
type Buf = SliceBuf<&'a BytesMut>;
fn into_buf(self) -> Self::Buf {
SliceBuf::new(self)
}
}
impl AsRef<[u8]> for BytesMut {
fn as_ref(&self) -> &[u8] {
let end = self.pos + self.len;