From 4886b445165dc4a1777752836104a274e348961e Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Wed, 2 Nov 2016 22:27:00 -0700 Subject: [PATCH] Add more conversion impls --- src/buf/byte.rs | 15 ++++++++++++++- src/bytes.rs | 6 ++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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()