From 599d089162607fb85dcdfaaf34289d440d98cd81 Mon Sep 17 00:00:00 2001 From: Stiopa Koltsov Date: Tue, 2 Mar 2021 02:46:25 +0000 Subject: [PATCH] impl From and From> for BytesMut `From` implementation is suboptimal: can be optimized for certain representations of `Bytes`. --- src/bytes_mut.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/bytes_mut.rs b/src/bytes_mut.rs index 61c0460ca..1d68e8560 100644 --- a/src/bytes_mut.rs +++ b/src/bytes_mut.rs @@ -1054,6 +1054,19 @@ impl<'a> From<&'a str> for BytesMut { } } +impl From> for BytesMut { + fn from(src: Vec) -> BytesMut { + BytesMut::from_vec(src) + } +} + +impl From for BytesMut { + fn from(src: Bytes) -> BytesMut { + // TODO: can be optimized for certain `Bytes` representations + BytesMut::from(src.as_ref()) + } +} + impl From for Bytes { fn from(src: BytesMut) -> Bytes { src.freeze()