-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue for (DoubleEnded)?Iterator::rfind #39480
Comments
Personally, I'd like to see |
It was already not the case that all iterator functionality sits in I just noticed the docs for rfind says "from the right" and should probably say "from the back", the r should be about reverse (like rev) and not left vs right (instead front vs back or forward vs reverse). |
Something that seems like a small drawback of having the method in The code that exists in rust today: #[stable(feature = "rust1", since = "1.0.0")]
impl<'a, I: Iterator + ?Sized> Iterator for &'a mut I {
type Item = I::Item;
fn next(&mut self) -> Option<I::Item> { (**self).next() }
fn size_hint(&self) -> (usize, Option<usize>) { (**self).size_hint() }
fn nth(&mut self, n: usize) -> Option<Self::Item> {
(**self).nth(n)
}
} Let's add specialization for This compiles fine: impl<'a, I: Iterator> Iterator for &'a mut I {
fn find<P>(&mut self, predicate: P) -> Option<Self::Item>
where P: FnMut(&Self::Item) -> bool,
{
(**self).find(predicate)
}
} And this, rfind can be specialized the same way: impl<'a, I: DoubleEndedIterator> DoubleEndedIterator for &'a mut I {
fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>
where P: FnMut(&Self::Item) -> bool,
{
(**self).rfind(predicate)
}
} Having trouble with this one -- Try 1, as part of the fn rposition<P>(&mut self, predicate: P) -> Option<usize> where
P: FnMut(Self::Item) -> bool,
Self: ExactSizeIterator + DoubleEndedIterator
{
(**self).rposition(predicate)
} First error (the rest are the same kind):
Try 2, we can use a separate specialization block: impl<'a, I: Iterator> Iterator for &'a mut I
where I: ExactSizeIterator + DoubleEndedIterator
{
fn rposition<P>(&mut self, predicate: P) -> Option<usize> where
P: FnMut(Self::Item) -> bool,
Self: ExactSizeIterator + DoubleEndedIterator
{
(**self).rposition(predicate)
}
} Error (We can't use the suggestion because "impl has stricter requirements than trait"): error[E0277]: the trait bound `P: ops::function::FnMut<(<I as iter::iterator::Iterator>::Item,)>` is not satisfied
--> src/libcore/iter/iterator.rs:2315:18
|
2315 | (**self).rposition(predicate)
| ^^^^^^^^^ the trait `ops::function::FnMut<(<I as iter::iterator::Iterator>::Item,)>` is not implemented for `P`
|
= help: consider adding a `where P: ops::function::FnMut<(<I as iter::iterator::Iterator>::Item,)>` bound |
With |
Breaking changes to stable I agree that @rfcbot fcp merge |
Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period is now complete. |
…chton Stabilize iterator methods in 1.27 - Closes rust-lang#39480, feature `iter_rfind` - `DoubleEndedIterator::rfind` - Closes rust-lang#44705, feature `iter_rfold` - `DoubleEndedIterator::rfold` - Closes rust-lang#45594, feature `iterator_try_fold` - `Iterator::try_fold` - `Iterator::try_for_each` - `DoubleEndedIterator::try_rfold`
PR: #39399
Unanswered: should this method be part of
DoubleEndedIterator
orIterator
?Pros:
Iterator
docswhere
clauseCons:
rev
,rposition
) aren't moved to DEIIterator
DoubleEndedIterator::rfind
if passed into a function instead ofIterator::find
Noting the above, should
Iterator::rev
andIterator::rposition
be moved to DEI as well?The text was updated successfully, but these errors were encountered: