Skip to content

7954: stream: impl FromStream for BTreeSet#74

Open
martin-augment wants to merge 3 commits intomasterfrom
pr-7954-2026-03-09-10-05-39
Open

7954: stream: impl FromStream for BTreeSet#74
martin-augment wants to merge 3 commits intomasterfrom
pr-7954-2026-03-09-10-05-39

Conversation

@martin-augment
Copy link
Copy Markdown
Owner

7954: To review by AI

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e60683b3-ed0a-40e1-8d8f-45d1891796bb

📥 Commits

Reviewing files that changed from the base of the PR and between a53cd3c and 090a530.

📒 Files selected for processing (2)
  • tokio-stream/src/stream_ext/collect.rs
  • tokio-stream/tests/stream_collect.rs

Walkthrough

This change adds support for collecting streams into a BTreeSet in tokio-stream. It implements the FromStream trait for BTreeSet where T implements Ord, along with the corresponding sealed::FromStreamPriv trait implementation. The implementation includes initialization, extension, and finalization methods that manage the BTreeSet throughout the collection process. An import for std::collections::BTreeSet is added to enable this functionality. A test case is included to verify that items are collected into a BTreeSet with correct ordering and behavior.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pr-7954-2026-03-09-10-05-39

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request extends the tokio-stream library by adding support for collecting items from an asynchronous stream directly into a BTreeSet. This enhancement provides a convenient and efficient way to gather unique and sorted elements from streams, improving the flexibility of stream processing within the Tokio ecosystem.

Highlights

  • New FromStream implementation: Implemented the FromStream trait for std::collections::BTreeSet, enabling direct collection of stream items into a BTreeSet.
  • Test coverage: Added a new test case to tokio-stream/tests/stream_collect.rs to validate the FromStream implementation for BTreeSet.
Changelog
  • tokio-stream/src/stream_ext/collect.rs
    • Imported std::collections::BTreeSet.
    • Implemented FromStream<T> for BTreeSet<T>.
    • Implemented sealed::FromStreamPriv<T> for BTreeSet<T>, including initialize, extend, and finalize methods.
  • tokio-stream/tests/stream_collect.rs
    • Imported std::collections::BTreeSet.
    • Added collect_btreeset_items asynchronous test to verify BTreeSet collection from a stream.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for collecting a stream into a BTreeSet. The implementation is correct and follows the existing patterns for other collection types. I've added one suggestion to improve the test coverage by verifying that duplicate items are handled correctly.

Comment on lines +77 to +79
tx.send(1).unwrap();
assert!(fut.is_woken());
assert_pending!(fut.poll());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This test correctly verifies ordering. To make it more comprehensive, consider also verifying that BTreeSet's uniqueness property is handled correctly by sending a duplicate item.

Suggested change
tx.send(1).unwrap();
assert!(fut.is_woken());
assert_pending!(fut.poll());
tx.send(1).unwrap();
assert!(fut.is_woken());
assert_pending!(fut.poll());
// Send a duplicate item.
tx.send(2).unwrap();
assert!(fut.is_woken());
assert_pending!(fut.poll());

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value:good-to-have; category:bug; feedback: The Gemini AI reviewer is correct! Currently the test verifies that the items in the BTreeSet are ordered (2 is sent first but it is printed after 1 in the final result). It would be good to extend the test with sending a duplicate (either 1 or 2) and verifying that there is only one occurrence of it in the result.

@augmentcode
Copy link
Copy Markdown

augmentcode bot commented Mar 9, 2026

🤖 Augment PR Summary

Summary: This PR adds StreamExt::collect() support for collecting stream items into a BTreeSet.

Changes:

  • Implemented `FromStream` for `std::collections::BTreeSet` (requires `T: Ord`)
  • Added the sealed `FromStreamPriv` plumbing to initialize/extend/finalize a `BTreeSet` during collection
  • Introduced a new test that drives a channel-backed stream and validates the final collected `BTreeSet`

Technical Notes: Uses BTreeSet::insert for per-item extension and mem::take to move the finalized set out at completion.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

@claude
Copy link
Copy Markdown

claude bot commented Mar 9, 2026

Code Review for stream: impl FromStream for BTreeSet

Overall: The implementation is clean and consistent with existing patterns. A useful addition.

Positives:

  • Correctly follows the established pattern used by Vec, String, and Box.
  • Correctly ignores size hints in initialize since BTreeSet has no pre-allocation API.
  • Test sends values out of order (2, 1) and asserts sorted output, nicely demonstrating BTreeSet behavior.
  • mem::take in finalize is consistent with all other collection implementations.

Issues and Suggestions:

  1. Missing empty_btreeset test. The test file includes empty_vec, empty_box_slice, and empty_string tests. For consistency, a test collecting an empty stream into a BTreeSet should be added.

  2. Missing deduplication test. BTreeSet silently drops duplicates, which is a key behavioral difference from Vec. A test sending duplicate values (e.g. 1, 1, 2) and asserting the result is the set {1, 2} would improve coverage and document this intentional behavior. The extend impl correctly returns true unconditionally (so streaming always continues), but a test would confirm deduplication works.

  3. CHANGELOG not updated. Per the project convention in tokio-stream/CHANGELOG.md, new features should be listed under Added. This PR warrants an entry such as: stream: implement FromStream for BTreeSet.

  4. Minor - import style. The new use std::collections::BTreeSet is the only non-core import added to collect.rs. Since tokio-stream does not target no_std this is fine, just noting for awareness.

Summary: The core implementation is correct and well-structured. The main gaps are a missing empty_btreeset test, a missing deduplication test, and no CHANGELOG entry. Otherwise ready to merge.

@martin-augment
Copy link
Copy Markdown
Owner Author

  1. Missing empty_btreeset test. The test file includes empty_vec, empty_box_slice, and empty_string tests. For consistency, a test collecting an empty stream into a BTreeSet should be added.

value:good-to-have; category:bug; feedback: The Claude AI reviewer is correct! For consistency with the other tests it would be good to test with no items, i.e. producing an empty BTreeSet.

@martin-augment
Copy link
Copy Markdown
Owner Author

2. Missing deduplication test. BTreeSet silently drops duplicates, which is a key behavioral difference from Vec. A test sending duplicate values (e.g. 1, 1, 2) and asserting the result is the set {1, 2} would improve coverage and document this intentional behavior. The extend impl correctly returns true unconditionally (so streaming always continues), but a test would confirm deduplication works.

value:good-to-have; category:bug; feedback: The Claude AI reviewer is correct! Currently the test verifies that the items in the BTreeSet are ordered (2 is sent first but it is printed after 1 in the final result). It would be good to extend the test with sending a duplicate (either 1 or 2) and verifying that there is only one occurrence of it in the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants