diff --git a/src/buf/byte.rs b/src/buf/byte.rs index ed73bbd..5149b96 100644 --- a/src/buf/byte.rs +++ b/src/buf/byte.rs @@ -1,4 +1,4 @@ -use {Buf, BufMut, BytesMut}; +use {Buf, BufMut, Bytes, BytesMut}; use std::{cmp, fmt}; @@ -186,6 +186,19 @@ impl BufMut for ByteBuf { } } +impl From for Bytes { + fn from(src: ByteBuf) -> Bytes { + let bytes = BytesMut::from(src); + bytes.freeze() + } +} + +impl From for BytesMut { + fn from(src: ByteBuf) -> BytesMut { + src.mem + } +} + impl fmt::Debug for ByteBuf { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { self.bytes().fmt(fmt) diff --git a/src/bytes.rs b/src/bytes.rs index 2e074f9..c9239a2 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -166,6 +166,12 @@ impl ops::Deref for Bytes { } } +impl From for Bytes { + fn from(src: BytesMut) -> Bytes { + src.freeze() + } +} + impl From> for Bytes { fn from(src: Vec) -> Bytes { BytesMut::from(src).freeze()