-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add Iterator::rfind. #39399
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
Add Iterator::rfind. #39399
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
6aa42ba
to
4af76e8
Compare
I think this is good. It's in line with the fold_ok ideas in two ways
|
Implementation-wise I'd write this directly using |
@bluss could you expand on the point about the location of the method? I vaguely recall that this was a thing in the past but can't recall specifics right now |
It's just that isn't it more natural to have a method directly on the trait where the method's functionality is enabled, instead of Provided method on the supertrait ( Since it's a method with a provided implementation, giving a specific impl for it should be easy either way. Though I have not explored it in detail, adding specializations for it is complicated (even incompatible?) if this method sits on |
I agree with @bluss on the fact that Unfortunately, that'd be a super-breaking change because implementors of The reason why I added this to |
I'd prefer to add |
@bluss I feel like it'd be off-putting to find this one method in |
@bluss ah ok, thanks for the explanation! IIRC one motivation for putting everything on |
I personally feel like precedent is good but we should also open up a dedicated issue for eventually moving these to the right place. |
I really think that once you recognize an error, you do your best to (1) fix it and (2) not repeat it. I'm not fond of the idea of sticking it in the Can't move the existing methods, but we can stop repeating the same error.
I don't think we serve users well this way, it's another inconsistent rule about std they will have to learn. (Any other trait that does the same thing?) The method's location should be decided by where its functionality is enabled, by the construction of the feature, not by how we want to present it. |
That's fair. For consistency, maybe we could try moving the other two methods and do a crater run to see the impact? |
Er well I guess my point is that I don't think we made an error. I find it quite useful to have a one-stop-shop for all iterator API documentation and would be sad to see it split across a number of traits. @rust-lang/libs do others have an opinion on this here? The specific question being debated is where a function like this should live. @bluss believes APIs should live on the trait they're associated with, where I personally prefer to keep all the iterator docs in one place. |
It's a well-intentioned kind of “nice” that leaves a spaghetti trail. (Should BufRead extension methods like |
Note that Of course, that's not really the right location, and having So I think the real question here is: what should be done for a method that's available only when two distinct traits ( Having the method live on |
|
@bluss Understood -- was just trying to give more historical context. @alexcrichton Given the context above, do you still feel strongly that the method should live on |
IMHO the only benefit to having more functions in iterator is being able to use However, in the case of this function, it's worth noting that because it's unstable, it can be moved after this PR is merged. We could always put this sort of discussion in the tracking issue. |
Ok let's just put this method on DEI then |
It has been moved. |
7767552
to
3cf485c
Compare
@bors: r+ |
📌 Commit 3cf485c has been approved by |
Thanks for working on this. There's a chance I'll propose |
Add Iterator::rfind. I found it weird that `Iterator` has `rpostition` but not `rfind`. This adds that method.
☀️ Test successful - status-appveyor, status-travis |
I found it weird that
Iterator
hasrpostition
but notrfind
. This adds that method.