Skip to content

Tracking Issue for Iterator::contains #127494

New issue

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

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

Already on GitHub? # to your account

Open
1 of 4 tasks
yonikremer opened this issue Jul 8, 2024 · 11 comments
Open
1 of 4 tasks

Tracking Issue for Iterator::contains #127494

yonikremer opened this issue Jul 8, 2024 · 11 comments
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@yonikremer
Copy link

yonikremer commented Jul 8, 2024

Feature gate: #![feature(iter_contains)]

This is a tracking issue for a method of the Iterator trait that checks whether an iterator contains an item.

A method of the iterator trait to check whether it contains an element.
It goes over all the elements in the iterator and checks if they are in the collection.

Public API

fn contains<Q: ?Sized>(&mut self, item: Q) -> bool
    where
        Q: PartialEq<Self::Item>,
        Self: Sized,

Steps / History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@yonikremer yonikremer added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jul 8, 2024
@tgross35

This comment has been minimized.

@yonikremer

This comment has been minimized.

@tgross35

This comment has been minimized.

@yonikremer

This comment has been minimized.

@zachs18
Copy link
Contributor

zachs18 commented Jul 11, 2024

cc rust-lang/rfcs#3624, which would be required for stabilizing this without breaking code that calls Itertools::contains without fully qualified syntax.

@yonikremer
Copy link
Author

@zachs18 I will rename the function to: has_item and that won't brake any code.

@yonikremer yonikremer changed the title Tracking Issue for Iterator::contains Tracking Issue for Iterator::has_item Jul 11, 2024
@tgross35
Copy link
Contributor

I think you can keep the function name contains under the gate iterator_contains - it's a better fit, consistent with other APIs (slice, Vec, HashMap, etc), and well known.

We need to resolve supertrait shadowing anyway, there are other itertools methods that we would like to pick up.

@yonikremer
Copy link
Author

@tgross35 it looks like the super trait shadowing pull request has been waiting to be merged for over a month. Why? can I help?

@tgross35
Copy link
Contributor

tgross35 commented Jul 11, 2024

Nothing really to be done there at the moment, it's just waiting on team discussion and for everyone to take the time to read it. A PR adding unstable Iterator::contains is not blocked by this RFC, only stabilization is (Iterator::intersperse is in the same boat).

@yonikremer
Copy link
Author

yonikremer commented Jul 11, 2024

I have the implementation, docs, and tests ready. I need to figure out whether to call it contains/has_item and then I can send a pull request. @tgross35 Should I just rename it to contains and submit a pull request for the unstable feature?

@Amanieu
Copy link
Member

Amanieu commented Jul 11, 2024

You should keep the original name contains. It's consistent with existing practice ([T]::contains) and we have a plan to resolve the conflict with itertools. Only if it turns out that this plan won't work then we will re-visit the naming of unstable iterator methods.

@Amanieu Amanieu changed the title Tracking Issue for Iterator::has_item Tracking Issue for Iterator::contains Jan 21, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants