From 55dfea8c18fcb412702319b58b4407248a5115ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=97=E6=B5=A6=E6=9C=88?= Date: Thu, 31 Jan 2019 03:05:15 +0800 Subject: [PATCH] Impl FromIterator<&'a u8> for `BytesMut`/`Bytes` (#244) --- src/bytes.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/bytes.rs b/src/bytes.rs index cb1aae4..db6cba7 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -926,6 +926,18 @@ impl FromIterator for Bytes { } } +impl<'a> FromIterator<&'a u8> for BytesMut { + fn from_iter>(into_iter: T) -> Self { + BytesMut::from_iter(into_iter.into_iter().map(|b| *b)) + } +} + +impl<'a> FromIterator<&'a u8> for Bytes { + fn from_iter>(into_iter: T) -> Self { + BytesMut::from_iter(into_iter).freeze() + } +} + impl PartialEq for Bytes { fn eq(&self, other: &Bytes) -> bool { self.inner.as_ref() == other.inner.as_ref()