From 2cf3f3f566b11a8aa46254253189dd4a7ae716fe Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Wed, 2 Oct 2019 21:15:19 -0400 Subject: [PATCH] FromStream for Arc<[T]> and Rc<[T]> --- src/vec/from_stream.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/vec/from_stream.rs b/src/vec/from_stream.rs index c813d49..f4ca9a9 100644 --- a/src/vec/from_stream.rs +++ b/src/vec/from_stream.rs @@ -1,5 +1,7 @@ use std::pin::Pin; use std::borrow::Cow; +use std::sync::Arc; +use std::rc::Rc; use crate::stream::{Extend, FromStream, IntoStream}; @@ -58,3 +60,39 @@ impl FromStream for Box<[T]> { }) } } + +impl FromStream for Rc<[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); + + Vec::from_stream(stream).await.into() + }) + } +} + +impl FromStream for Arc<[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); + + Vec::from_stream(stream).await.into() + }) + } +}