From 8e127980389719aa9c2a16c832bce7eb579ba084 Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Wed, 2 Oct 2019 21:11:50 -0400 Subject: [PATCH] impl FromStream for Cow<[T]> --- src/vec/from_stream.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/vec/from_stream.rs b/src/vec/from_stream.rs index 26196af..8d723b4 100644 --- a/src/vec/from_stream.rs +++ b/src/vec/from_stream.rs @@ -1,4 +1,5 @@ use std::pin::Pin; +use std::borrow::Cow; use crate::stream::{Extend, FromStream, IntoStream}; @@ -21,3 +22,21 @@ impl FromStream for Vec { }) } } + +impl<'b, T: Clone> FromStream for Cow<'b, [T]> { + #[inline] + fn from_stream<'a, S: IntoStream>( + stream: S, + ) -> Pin + 'a>> + where + ::IntoStream: 'a, + { + let stream = stream.into_stream(); + + Box::pin(async move { + pin_utils::pin_mut!(stream); + + Cow::Owned(FromStream::from_stream(stream).await) + }) + } +}