diff --git a/src/bytes.rs b/src/bytes.rs index 9a25688a7892cfd2aa332451d0953132566a5afb..2e074f94f87b72f2a516835cdf02ed35ddbd9bce 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -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;