stream: impl FromStream for BTreeSet (#7954)

This commit is contained in:
figsoda
2026-03-09 10:20:21 +00:00
committed by GitHub
parent 961757f548
commit aa1e7e2b9d
2 changed files with 43 additions and 0 deletions
+20
View File
@@ -6,6 +6,7 @@ use core::mem;
use core::pin::Pin;
use core::task::{ready, Context, Poll};
use pin_project_lite::pin_project;
use std::collections::BTreeSet;
// Do not export this struct until `FromStream` can be unsealed.
pin_project! {
@@ -135,6 +136,25 @@ impl<T> sealed::FromStreamPriv<T> for Vec<T> {
}
}
impl<T: Ord> FromStream<T> for BTreeSet<T> {}
impl<T: Ord> sealed::FromStreamPriv<T> for BTreeSet<T> {
type InternalCollection = BTreeSet<T>;
fn initialize(_: sealed::Internal, _lower: usize, _upper: Option<usize>) -> BTreeSet<T> {
BTreeSet::new()
}
fn extend(_: sealed::Internal, collection: &mut BTreeSet<T>, item: T) -> bool {
collection.insert(item);
true
}
fn finalize(_: sealed::Internal, collection: &mut BTreeSet<T>) -> BTreeSet<T> {
mem::take(collection)
}
}
impl<T> FromStream<T> for Box<[T]> {}
impl<T> sealed::FromStreamPriv<T> for Box<[T]> {