Added FromStream + Extend for BTreeSet
parent
6c2ffd7181
commit
3160dc8189
@ -0,0 +1,16 @@
|
||||
use std::pin::Pin;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::stream::{Extend, IntoStream};
|
||||
|
||||
impl<T: Ord> Extend<T> for BTreeSet<T> {
|
||||
fn stream_extend<'a, S: IntoStream<Item = T> + 'a>(
|
||||
&'a mut self,
|
||||
stream: S,
|
||||
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
|
||||
Box::pin(stream.into_stream().for_each(move |item| {
|
||||
self.insert(item);
|
||||
}))
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
use std::pin::Pin;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use crate::stream::{Extend, FromStream, IntoStream};
|
||||
|
||||
impl<T: Ord> FromStream<T> for BTreeSet<T> {
|
||||
#[inline]
|
||||
fn from_stream<'a, S: IntoStream<Item = T>>(
|
||||
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 = BTreeSet::new();
|
||||
out.stream_extend(stream).await;
|
||||
out
|
||||
})
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
//! The Rust B-Tree Set
|
||||
|
||||
mod extend;
|
||||
mod from_stream;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use std::collections::BTreeSet;
|
Loading…
Reference in New Issue