Add more conversion impls

This commit is contained in:
Carl Lerche
2016-11-02 22:27:00 -07:00
parent a367a723d8
commit 4886b44516
2 changed files with 20 additions and 1 deletions
+14 -1
View File
@@ -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<ByteBuf> for Bytes {
fn from(src: ByteBuf) -> Bytes {
let bytes = BytesMut::from(src);
bytes.freeze()
}
}
impl From<ByteBuf> 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)
+6
View File
@@ -166,6 +166,12 @@ impl ops::Deref for Bytes {
}
}
impl From<BytesMut> for Bytes {
fn from(src: BytesMut) -> Bytes {
src.freeze()
}
}
impl From<Vec<u8>> for Bytes {
fn from(src: Vec<u8>) -> Bytes {
BytesMut::from(src).freeze()