Open traviscross opened 5 months ago
To see which iterator methods we may want to add to the new ranges, I did an informal search on Github using the following query:
language:rust NOT is:fork /\W\s*\(\s*\w*\s*\.\.=?\s*\w*\s*\)\s*.\s*method\s*\(/
I matched on anything that looks like ( <> .. <> )
or ( <> ..= <> )
that is not immediately
preceded by some identifier character, to avoid matching things like vec.drain(..).map(_)
.
Example for map
: search.
This isn't perfect but captures a rough amount of usage. Just looking by the number of matches:
map
: 65.8krev
: 23.2kcollect
: 9.9kfor_each
: 8.5kstep_by
: 8.3kfilter
: 8.2kflat_map
: 4.2kfold
: 3.5kzip
: 3.4kfilter_map
: 1.6kfind
: 1.5kchain
: 1.4ktake_while
: 1.1kall
: 1.1kcycle
: 0.7kenumerate
: 0.6kscan
: 0.4kproduct
: 0.4kfind_map
: 0.3kany
: 0.3ksum
: 0.2ktake
: 0.2kskip
: 0.1ktry_*
: 0.1kmin*
: 0.1kmax*
: 0.1kmap_while
: 0.1kposition
: 0.1kskip_while
: 0.1kcount
: 0.1kreduce
: 0.1knth
: 0.1kunzip
: 0I personally think filter
is a decent cut-off, which gives the inherent methods map
, rev
, collect
, for_each
, step_by
, filter
.
Any reason you left out step_by
from your final list?
@pitaj Nope, just a clerical error. I fixed it.
another common method that was omitted: len()
(idk how many instances since github gave an error when I tried the search)
@programmerjake There is no len()
on Iterator
.
@programmerjake There is no
len()
onIterator
.
there is on ExactSizeIterator
: https://doc.rust-lang.org/std/ops/struct.Range.html#impl-ExactSizeIterator-for-Range%3Ci8%3E
Right. I think honestly len
probably makes sense regardless of whether an iterator implements it and/or how many people currently are calling it.
I'd rather we have a better solution for len
than ExactSizeIterator
since, as proposed, even the new iterators for Range<u32>
and RangeInclusive<i16>
don't implement it.
Ugh I forgot, there's still the problem that fn len(&self) -> usize
doesn't work on ranges larger than usize, nor the 0..=usize::MAX
range for usize
itself.
Let's continue that discussion about which methods to add in a separate issue here rather than on the tracking issue.
@rustbot labels -A-edition-2024 +A-maybe-future-edition -S-tracking-at-risk
This is, unfortunately, not likely to have all the pieces in place in time to ship with the Rust 2024 edition, so we're going to drop the label.
Thanks to all those who have been working on this, and we hope to see this ship in a future edition.
This is, unfortunately, not likely to have all the pieces in place in time to ship with the Rust 2024 edition, so we're going to drop the label.
What things are missing so far?
What things are missing so far?
See the issue description above. We need to check off all of those boxes in order to land this in any edition.
This is a tracking issue for the RFC 3550: New range types
The feature gate for the issue is
#![feature(new_range)]
.Tracking issue for the library change:
About tracking issues
Tracking issues are used to record the overall progress of implementation. They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions. A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature. Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
Unresolved Questions
#[cfg(overflow_checks)]
just magically work?" (see here).Related
cc @pitaj