Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for (DoubleEnded)?Iterator::rfind #39480
Comments
alexcrichton
added
B-unstable
T-libs
labels
Feb 3, 2017
This comment has been minimized.
This comment has been minimized.
andrewjstone
commented
Jun 11, 2017
|
Personally, I'd like to see |
This comment has been minimized.
This comment has been minimized.
|
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). |
Mark-Simulacrum
added
the
C-tracking-issue
label
Jul 22, 2017
dtolnay
referenced this issue
Sep 19, 2017
Merged
Add iterator method .rfold(init, function); the reverse of fold #44682
bluss
referenced this issue
Sep 19, 2017
Closed
Tracking issue for DoubleEndedIterator::rfold (feature `iter_rfold`) #44705
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
With |
This comment has been minimized.
This comment has been minimized.
|
Breaking changes to stable I agree that @rfcbot fcp merge |
rfcbot
added
the
proposed-final-comment-period
label
Mar 17, 2018
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 17, 2018
•
|
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 comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 19, 2018
|
|
rfcbot
added
final-comment-period
and removed
proposed-final-comment-period
labels
Mar 19, 2018
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 29, 2018
|
The final comment period is now complete. |
clarfon commentedFeb 3, 2017
PR: #39399
Unanswered: should this method be part of
DoubleEndedIteratororIterator?Pros:
IteratordocswhereclauseCons:
rev,rposition) aren't moved to DEIIteratorDoubleEndedIterator::rfindif passed into a function instead ofIterator::findNoting the above, should
Iterator::revandIterator::rpositionbe moved to DEI as well?