async_std/collections/btree_map/
from_stream.rs

1use std::collections::BTreeMap;
2use std::pin::Pin;
3
4use crate::prelude::*;
5use crate::stream::{self, FromStream, IntoStream};
6
7impl<K: Ord, V> FromStream<(K, V)> for BTreeMap<K, V> {
8    #[inline]
9    fn from_stream<'a, S: IntoStream<Item = (K, V)> + 'a>(
10        stream: S,
11    ) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
12        let stream = stream.into_stream();
13
14        Box::pin(async move {
15            let mut out = BTreeMap::new();
16            stream::extend(&mut out, stream).await;
17            out
18        })
19    }
20}