Added FromStream + Extend for BTreeMap
parent
244c5159df
commit
de2bc1e83b
@ -0,0 +1,16 @@
|
||||
use std::pin::Pin;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::stream::{Extend, IntoStream};
|
||||
|
||||
impl<K: Ord, V> Extend<(K, V)> for BTreeMap<K, V> {
|
||||
fn stream_extend<'a, S: IntoStream<Item = (K, V)> + 'a>(
|
||||
&'a mut self,
|
||||
stream: S,
|
||||
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
|
||||
Box::pin(stream.into_stream().for_each(move |(k, v)| {
|
||||
self.insert(k, v);
|
||||
}))
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
use std::pin::Pin;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::stream::{Extend, FromStream, IntoStream};
|
||||
|
||||
impl<K: Ord, V> FromStream<(K, V)> for BTreeMap<K, V> {
|
||||
#[inline]
|
||||
fn from_stream<'a, S: IntoStream<Item = (K, V)>>(
|
||||
stream: S,
|
||||
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
|
||||
where
|
||||
<S as IntoStream>::IntoStream: 'a,
|
||||
{
|
||||
let stream = stream.into_stream();
|
||||
|
||||
Box::pin(async move {
|
||||
pin_utils::pin_mut!(stream);
|
||||
|
||||
let mut out = BTreeMap::new();
|
||||
out.stream_extend(stream).await;
|
||||
out
|
||||
})
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
//! The Rust B-Tree Map
|
||||
|
||||
mod extend;
|
||||
mod from_stream;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use std::collections::BTreeMap;
|
Loading…
Reference in New Issue