-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement DoubleEnded and ExactSize for Take<Repeat> and Take<RepeatWith> #106943
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
Conversation
…ith> Repeat iterator always returns the same element and behaves the same way backwards and forwards. Take iterator can trivially implement backwards iteration over Repeat inner iterator by simply doing forwards iteration. DoubleEndedIterator is not currently implemented for Take<Repeat<T>> because Repeat doesn’t implement ExactSizeIterator which is a required bound on DEI implementation for Take. Similarly, since Repeat is an infinite iterator which never stops, Take can trivially know how many elements it’s going to return. This allows implementing ExactSizeIterator on Take<Repeat<T>>. While at it, observe that ExactSizeIterator can also be implemented for Take<RepeatWhile<F>> so add that implementation too. Since in contrast to Repeat, RepeatWhile doesn’t guarante to always return the same value, DoubleEndedIterator isn’t implemented. Those changes render core::iter::repeat_n somewhat redundant. Issue: rust-lang#104434 Issue: rust-lang#104729
r? @cuviper (rustbot has picked a reviewer for you, use r? to override) |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
@rustbot label +T-libs-api -T-libs |
45de24d
to
5d1590d
Compare
r? libs-api |
Reassigning BurntSushi's reviews because based on r? rust-lang/libs-api |
I believe this requires an ACP, since it introduces an insta-stable change by adding a new implementation of an existing stable trait on an existing stable type. Please open one (if you haven't already). Then link it here and mark the PR as @rustbot label -S-waiting-on-review +S-waiting-on-author |
Sorry, I missed the requirement for ACP. So actually, rather than creating a new one, I’ve just pinged ACP for repeat_n. This approach was actually suggested there already. The ACP is: rust-lang/libs-team#120 |
@rustbot label -S-waiting-on-author +S-waiting-on-ACP |
... is it really an ExactSizeIterator if it's infinite? |
This only adds that impl for |
... I'll uh... |
…lnay Implement DoubleEnded and ExactSize for Take<Repeat> and Take<RepeatWith> Repeat iterator always returns the same element and behaves the same way backwards and forwards. Take iterator can trivially implement backwards iteration over Repeat inner iterator by simply doing forwards iteration. DoubleEndedIterator is not currently implemented for Take<Repeat<T>> because Repeat doesn’t implement ExactSizeIterator which is a required bound on DEI implementation for Take. Similarly, since Repeat is an infinite iterator which never stops, Take can trivially know how many elements it’s going to return. This allows implementing ExactSizeIterator on Take<Repeat<T>>. While at it, observe that ExactSizeIterator can also be implemented for Take<RepeatWhile<F>> so add that implementation too. Since in contrast to Repeat, RepeatWhile doesn’t guarante to always return the same value, DoubleEndedIterator isn’t implemented. Those changes render core::iter::repeat_n somewhat redundant. Issue: rust-lang#104434 Issue: rust-lang#104729 - [ ] ACP: rust-lang/libs-team#120 (this is actually ACP for repeat_n but this is nearly the same functionality so hijacking it so both approaches can be discussed in one place)
💔 Test failed - checks-actions |
This comment has been minimized.
This comment has been minimized.
Needs a rebase to fix the conflict with #120486. |
ebf79b5
to
994e712
Compare
- fn advance_back_by(&mut self, n: usize) -> Result<(), NonZeroUsize> {
+ fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> { @bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (f24a6ba): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary -3.1%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 750.979s -> 749.822s (-0.15%) |
After rust/rust-lang#106943 the part about `ExactSizeIterator` is no longer valid
…s-not-that-special-anymore, r=jhpratt Remove outdated documentation for `repeat_n` After rust-lang#106943, which made `Take<Repeat<I>>` implement `ExactSizeIterator`, part of documentation about difference from `repeat(x).take(n)` is no longer valid. `@rustbot` labels: +A-docs, +A-iterators
…s-not-that-special-anymore, r=jhpratt Remove outdated documentation for `repeat_n` After rust-lang#106943, which made `Take<Repeat<I>>` implement `ExactSizeIterator`, part of documentation about difference from `repeat(x).take(n)` is no longer valid. ``@rustbot`` labels: +A-docs, +A-iterators
…s-not-that-special-anymore, r=jhpratt Remove outdated documentation for `repeat_n` After rust-lang#106943, which made `Take<Repeat<I>>` implement `ExactSizeIterator`, part of documentation about difference from `repeat(x).take(n)` is no longer valid. ```@rustbot``` labels: +A-docs, +A-iterators
…s-not-that-special-anymore, r=jhpratt Remove outdated documentation for `repeat_n` After rust-lang#106943, which made `Take<Repeat<I>>` implement `ExactSizeIterator`, part of documentation about difference from `repeat(x).take(n)` is no longer valid. ````@rustbot```` labels: +A-docs, +A-iterators
Rollup merge of rust-lang#131858 - AnthonyMikh:AnthonyMikh/repeat_n-is-not-that-special-anymore, r=jhpratt Remove outdated documentation for `repeat_n` After rust-lang#106943, which made `Take<Repeat<I>>` implement `ExactSizeIterator`, part of documentation about difference from `repeat(x).take(n)` is no longer valid. ````@rustbot```` labels: +A-docs, +A-iterators
Repeat iterator always returns the same element and behaves the same way
backwards and forwards. Take iterator can trivially implement backwards
iteration over Repeat inner iterator by simply doing forwards iteration.
DoubleEndedIterator is not currently implemented for Take<Repeat>
because Repeat doesn’t implement ExactSizeIterator which is a required
bound on DEI implementation for Take.
Similarly, since Repeat is an infinite iterator which never stops, Take
can trivially know how many elements it’s going to return. This allows
implementing ExactSizeIterator on Take<Repeat>.
While at it, observe that ExactSizeIterator can also be implemented for
Take<RepeatWhile> so add that implementation too. Since in contrast
to Repeat, RepeatWhile doesn’t guarante to always return the same value,
DoubleEndedIterator isn’t implemented.
Those changes render core::iter::repeat_n somewhat redundant.
Issue: #104434
Issue: #104729
iter::repeat_n
from itertools libs-team#120 (this is actually ACP for repeat_n but this is nearly the same functionality so hijacking it so both approaches can be discussed in one place)