Skip to content

Commit 8e12798

Browse files
committed
impl FromStream for Cow<[T]>
1 parent b217457 commit 8e12798

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/vec/from_stream.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::pin::Pin;
2+
use std::borrow::Cow;
23

34
use crate::stream::{Extend, FromStream, IntoStream};
45

@@ -21,3 +22,21 @@ impl<T> FromStream<T> for Vec<T> {
2122
})
2223
}
2324
}
25+
26+
impl<'b, T: Clone> FromStream<T> for Cow<'b, [T]> {
27+
#[inline]
28+
fn from_stream<'a, S: IntoStream<Item = T>>(
29+
stream: S,
30+
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
31+
where
32+
<S as IntoStream>::IntoStream: 'a,
33+
{
34+
let stream = stream.into_stream();
35+
36+
Box::pin(async move {
37+
pin_utils::pin_mut!(stream);
38+
39+
Cow::Owned(FromStream::from_stream(stream).await)
40+
})
41+
}
42+
}

0 commit comments

Comments
 (0)