-
Notifications
You must be signed in to change notification settings - Fork 21
Adding position to Enumerate #435
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
Comments
The name conflicts with |
cc the IRLO thread, which has some good comments: https://internals.rust-lang.org/t/rust-lacks-enumerated-position-to-get-the-current-count/21449/7?u=scottmcm |
So could offset also get added to enumerated then |
You would have to subtract 1 anyways, because the initial position will actually be an item you haven't iterated to yet. |
@x4exr Do you have a practical use-case in mind? It's not entirely clear if you want what you say you want, because of the whole "the actual first position will be 0, even before you call |
Yes I need this method to measure the number of iterations made when I call a function such as parse string with Mt iterator inside |
Ah, so you're going to call... hm, it can't be let start = iter.current_count();
my_parser_that_accepts_iterators(iter);
let end = iter.current_count();
let iterations = end - start; |
Yes, I was even thinking |
Another option that avoids the conflicts entirely, meaning you can use any name you want: #[inline]
pub fn count(this: &Self) -> usize {
this.count
} |
why call it |
Yes, it doesn't become a method, so there's no name conflict. It's called like |
We discussed this in the libs-api meeting and are happy to accept this. However we feel that the name |
While |
What about |
What does it have to do with peek? |
It's a preview of what |
We did discuss this issue in the meeting but we felt like this was unlikely to be an issue in practice. While it follows the same pattern as the |
We'll have plenty of time to argue over what Pantone chips to use, let's just get it on nightly. |
add next_index to Enumerate Proposal: rust-lang/libs-team#435 Tracking Issue: rust-lang#130711 This basically just reopens rust-lang#130682 but squashed and with the new function and the feature gate renamed to `next_index.` There are two questions I have already: - Shouldn't we add test coverage for that? I'm happy to provide some, but I might need a pointer to where these test would be. - Maybe I could actually also add a doctest? - For now, I just renamed the feature name in the unstable attribute to `next_index`, as well, so it matches the new name of the function. Is that okay? And can I just do that and use any string, or is there a sealed list of features defined somewhere where I also need to change the name?
Rollup merge of rust-lang#139533 - jogru0:130711, r=Mark-Simulacrum add next_index to Enumerate Proposal: rust-lang/libs-team#435 Tracking Issue: rust-lang#130711 This basically just reopens rust-lang#130682 but squashed and with the new function and the feature gate renamed to `next_index.` There are two questions I have already: - Shouldn't we add test coverage for that? I'm happy to provide some, but I might need a pointer to where these test would be. - Maybe I could actually also add a doctest? - For now, I just renamed the feature name in the unstable attribute to `next_index`, as well, so it matches the new name of the function. Is that okay? And can I just do that and use any string, or is there a sealed list of features defined somewhere where I also need to change the name?
add next_index to Enumerate Proposal: rust-lang/libs-team#435 Tracking Issue: #130711 This basically just reopens #130682 but squashed and with the new function and the feature gate renamed to `next_index.` There are two questions I have already: - Shouldn't we add test coverage for that? I'm happy to provide some, but I might need a pointer to where these test would be. - Maybe I could actually also add a doctest? - For now, I just renamed the feature name in the unstable attribute to `next_index`, as well, so it matches the new name of the function. Is that okay? And can I just do that and use any string, or is there a sealed list of features defined somewhere where I also need to change the name?
add next_index to Enumerate Proposal: rust-lang/libs-team#435 Tracking Issue: rust-lang#130711 This basically just reopens rust-lang#130682 but squashed and with the new function and the feature gate renamed to `next_index.` There are two questions I have already: - Shouldn't we add test coverage for that? I'm happy to provide some, but I might need a pointer to where these test would be. - Maybe I could actually also add a doctest? - For now, I just renamed the feature name in the unstable attribute to `next_index`, as well, so it matches the new name of the function. Is that okay? And can I just do that and use any string, or is there a sealed list of features defined somewhere where I also need to change the name?
Uh oh!
There was an error while loading. Please reload this page.
Proposal
Adding position function to Enumerate struct.
Problem statement
Other than doing next() which will progress the position, there is no straight forward way to get the position. If you call something that uses your iterator, you cant know how far it progressed without knowing the position start and end.
Motivating examples or use cases
Solution sketch
Alternatives
Putting Peek around Enumerate, then doing .peek() and subtracting 1 from the position. The issue with this is if you are at the end of the iteration, you get None and need to store the end position else where. This also uses peek in a way that is unnatural and unneccesary. Its over complicated
Links and related work
position
toEnumerate
rust#129784 Is a pull request I opened for thisWhat happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: