From a367a723d824e5a21bf08a94980522f16a91430e Mon Sep 17 00:00:00 2001 From: Carl Lerche <me@carllerche.com> Date: Wed, 2 Nov 2016 14:31:57 -0700 Subject: [PATCH] Impl IntoBuf for Bytes and BytesMut --- src/bytes.rs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/bytes.rs b/src/bytes.rs index 9a25688..2e074f9 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; -- GitLab