diff --git a/src/collections/btree_set/extend.rs b/src/collections/btree_set/extend.rs new file mode 100644 index 0000000..2fd1d1d --- /dev/null +++ b/src/collections/btree_set/extend.rs @@ -0,0 +1,16 @@ +use std::pin::Pin; +use std::collections::BTreeSet; + +use crate::prelude::*; +use crate::stream::{Extend, IntoStream}; + +impl Extend for BTreeSet { + fn stream_extend<'a, S: IntoStream + 'a>( + &'a mut self, + stream: S, + ) -> Pin + 'a>> { + Box::pin(stream.into_stream().for_each(move |item| { + self.insert(item); + })) + } +} diff --git a/src/collections/btree_set/from_stream.rs b/src/collections/btree_set/from_stream.rs new file mode 100644 index 0000000..b4b654f --- /dev/null +++ b/src/collections/btree_set/from_stream.rs @@ -0,0 +1,24 @@ +use std::pin::Pin; +use std::collections::BTreeSet; + +use crate::stream::{Extend, FromStream, IntoStream}; + +impl FromStream for BTreeSet { + #[inline] + fn from_stream<'a, S: IntoStream>( + stream: S, + ) -> Pin + 'a>> + where + ::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 + }) + } +} diff --git a/src/collections/btree_set/mod.rs b/src/collections/btree_set/mod.rs new file mode 100644 index 0000000..e8a572a --- /dev/null +++ b/src/collections/btree_set/mod.rs @@ -0,0 +1,7 @@ +//! The Rust B-Tree Set + +mod extend; +mod from_stream; + +#[doc(inline)] +pub use std::collections::BTreeSet; diff --git a/src/collections/mod.rs b/src/collections/mod.rs index 4ed8e35..d77d443 100644 --- a/src/collections/mod.rs +++ b/src/collections/mod.rs @@ -7,8 +7,10 @@ pub mod vec_deque; pub mod hash_map; pub mod hash_set; pub mod btree_map; +pub mod btree_set; pub use vec_deque::VecDeque; pub use hash_map::HashMap; pub use hash_set::HashSet; pub use btree_map::BTreeMap; +pub use btree_set::BTreeSet;