Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: take_while_inclusive takes iterator by value #709

Merged
merged 1 commit into from
Aug 5, 2023
Merged

fix: take_while_inclusive takes iterator by value #709

merged 1 commit into from
Aug 5, 2023

Conversation

abhikjain360
Copy link
Contributor

@abhikjain360 abhikjain360 commented Jul 1, 2023

this helps in case TakeWhileInclusive is returned from a function, as otherwise we would be returning a struct which takes a reference from a locally created iterator.

example code which breaks, but shouldn't:

use itertools::Itertools;

struct Entry {
    constraint: bool,
}

struct List {
    entries: Vec<Entry>,
}

impl List {
    fn special(&self) -> impl Iterator<Item = &Entry> {
        self
            .entries
            .iter()
            .take_while_inclusive(|entry| entry.constraint)
    }
}

Rust Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f602ba3c6e7c2ab2f5132a0b40b80ceb

this helps in case TakeWhileInclusive is returned from a function, as
otherwise we would be returning a struct which takes a reference from a
locally created iterator.
@Philippe-Cholet
Copy link
Member

Philippe-Cholet commented Jul 2, 2023

I thought you had a point so I looked at the methods in trait Iterator to find the way the "std" considers this.

There are 4 cases:

  • no change (size_hint): immutable borrow ;
  • transfer ownership to another iterator type (such as take_while...): take by value ;
  • consume the iterator completely (such as count/last/max...): take by value ;
  • consume only part of the iterator (such as find/all/try_collect...): mutably borrow.

take_while_inclusive is like take_while, it returns another iterator type. So I think it should take by value. People that does not want that can still do some_it.by_ref().take_while_inclusive(...) then do something else with what remains in some_it.

tldr I fully agree with you.

PS: It's a breaking change but take_while_inclusive is really new (appeared in "0.11.0" a few days ago) so it won't be a big issue for people if it's fixed soon.

@phimuemue
Copy link
Member

I think @Philippe-Cholet's assessment is correct.

Thus, I'd like to merge this. @jswrenn Do you have objections?

@abhikjain360
Copy link
Contributor Author

Hi @phimuemue @jswrenn ,
any updates on this or #710?
I think by now it is late enough that you probably need to release this fix in a separate release 😅 .
I can add fixes for other methods mentioned in #710 if that would help get this merged.

Thanks!

@phimuemue
Copy link
Member

Thanks a lot.

bors r+

@bors
Copy link
Contributor

bors bot commented Aug 5, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit 79bfebb into rust-itertools:master Aug 5, 2023
@jswrenn
Copy link
Member

jswrenn commented Aug 31, 2023

Thank you for this! Apologizes for not releasing this fast enough to avoid a breaking release; I was on an extended bicycle tour. I'll get out a release soon.

@meithecatte
Copy link

@jswrenn I just hit this issue and found this PR. Just wanna make sure that you haven't forgot about the release. Thanks for your work, itertools is a very useful crate ;3

@jswrenn jswrenn added this to the next milestone Nov 14, 2023
@jswrenn jswrenn mentioned this pull request Nov 14, 2023
facebook-github-bot pushed a commit to facebookincubator/reindeer that referenced this pull request Oct 14, 2024
Summary:
[Release Notes for 0.12.0](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md#0120)
[Release Notes for 0.12.1](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md#0121)

### Breaking
- Made `take_while_inclusive` consume iterator by value ([#709](rust-itertools/itertools#709)) --- there are [2 usages](https://www.internalfb.com/code/search?q=repo%3Afbcode%20take_while_inclusive&lang_filter=rust) in fbcode, verified both manually
- Added `Clone` bound to `Unique` ([#777](rust-itertools/itertools#777)) --- there are [37 usages](https://fburl.com/code/hp7vdlch) in fbcode, CI will tell if it breaks

Reviewed By: anps77

Differential Revision: D64305791

fbshipit-source-id: fe99131b206905133c4d2b75693090f5ce44f4ca
facebook-github-bot pushed a commit to facebookexperimental/rust-shed that referenced this pull request Oct 14, 2024
Summary:
[Release Notes for 0.12.0](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md#0120)
[Release Notes for 0.12.1](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md#0121)

### Breaking
- Made `take_while_inclusive` consume iterator by value ([#709](rust-itertools/itertools#709)) --- there are [2 usages](https://www.internalfb.com/code/search?q=repo%3Afbcode%20take_while_inclusive&lang_filter=rust) in fbcode, verified both manually
- Added `Clone` bound to `Unique` ([#777](rust-itertools/itertools#777)) --- there are [37 usages](https://fburl.com/code/hp7vdlch) in fbcode, CI will tell if it breaks

Reviewed By: anps77

Differential Revision: D64305791

fbshipit-source-id: fe99131b206905133c4d2b75693090f5ce44f4ca
facebook-github-bot pushed a commit to facebook/sapling that referenced this pull request Oct 14, 2024
Summary:
[Release Notes for 0.12.0](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md#0120)
[Release Notes for 0.12.1](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md#0121)

### Breaking
- Made `take_while_inclusive` consume iterator by value ([#709](rust-itertools/itertools#709)) --- there are [2 usages](https://www.internalfb.com/code/search?q=repo%3Afbcode%20take_while_inclusive&lang_filter=rust) in fbcode, verified both manually
- Added `Clone` bound to `Unique` ([#777](rust-itertools/itertools#777)) --- there are [37 usages](https://fburl.com/code/hp7vdlch) in fbcode, CI will tell if it breaks

Reviewed By: anps77

Differential Revision: D64305791

fbshipit-source-id: fe99131b206905133c4d2b75693090f5ce44f4ca
facebook-github-bot pushed a commit to facebook/errpy that referenced this pull request Oct 14, 2024
Summary:
[Release Notes for 0.12.0](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md#0120)
[Release Notes for 0.12.1](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md#0121)

### Breaking
- Made `take_while_inclusive` consume iterator by value ([#709](rust-itertools/itertools#709)) --- there are [2 usages](https://www.internalfb.com/code/search?q=repo%3Afbcode%20take_while_inclusive&lang_filter=rust) in fbcode, verified both manually
- Added `Clone` bound to `Unique` ([#777](rust-itertools/itertools#777)) --- there are [37 usages](https://fburl.com/code/hp7vdlch) in fbcode, CI will tell if it breaks

Reviewed By: anps77

Differential Revision: D64305791

fbshipit-source-id: fe99131b206905133c4d2b75693090f5ce44f4ca
facebook-github-bot pushed a commit to facebook/hhvm that referenced this pull request Oct 14, 2024
Summary:
[Release Notes for 0.12.0](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md#0120)
[Release Notes for 0.12.1](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md#0121)

### Breaking
- Made `take_while_inclusive` consume iterator by value ([#709](rust-itertools/itertools#709)) --- there are [2 usages](https://www.internalfb.com/code/search?q=repo%3Afbcode%20take_while_inclusive&lang_filter=rust) in fbcode, verified both manually
- Added `Clone` bound to `Unique` ([#777](rust-itertools/itertools#777)) --- there are [37 usages](https://fburl.com/code/hp7vdlch) in fbcode, CI will tell if it breaks

Reviewed By: anps77

Differential Revision: D64305791

fbshipit-source-id: fe99131b206905133c4d2b75693090f5ce44f4ca
facebook-github-bot pushed a commit to facebookincubator/below that referenced this pull request Oct 14, 2024
Summary:
[Release Notes for 0.12.0](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md#0120)
[Release Notes for 0.12.1](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md#0121)

### Breaking
- Made `take_while_inclusive` consume iterator by value ([#709](rust-itertools/itertools#709)) --- there are [2 usages](https://www.internalfb.com/code/search?q=repo%3Afbcode%20take_while_inclusive&lang_filter=rust) in fbcode, verified both manually
- Added `Clone` bound to `Unique` ([#777](rust-itertools/itertools#777)) --- there are [37 usages](https://fburl.com/code/hp7vdlch) in fbcode, CI will tell if it breaks

Reviewed By: anps77

Differential Revision: D64305791

fbshipit-source-id: fe99131b206905133c4d2b75693090f5ce44f4ca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants