2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-12-10 07:14:33 +00:00
async-std/src/collections/btree_map/from_stream.rs
Stjepan Glavina 548733e5d5
Cleanup stream traits (#487)
* Cleanup stream traits

* Fix docs
2019-11-09 11:22:09 +01:00

22 lines
573 B
Rust

use std::collections::BTreeMap;
use std::pin::Pin;
use crate::prelude::*;
use crate::stream::{self, FromStream, IntoStream};
impl<K: Ord, V> FromStream<(K, V)> for BTreeMap<K, V> {
#[inline]
fn from_stream<'a, S: IntoStream<Item = (K, V)> + 'a>(
stream: S,
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {
pin_utils::pin_mut!(stream);
let mut out = BTreeMap::new();
stream::extend(&mut out, stream).await;
out
})
}
}