Skip to content
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

Implement DoubleEnded and ExactSize for Take<Repeat> and Take<RepeatWith> #106943

Merged
merged 1 commit into from
Aug 17, 2024

Commits on Jan 16, 2023

  1. Implement DoubleEnded and ExactSize for Take<Repeat> and Take<RepeatW…

    …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
    mina86 committed Jan 16, 2023
    Configuration menu
    Copy the full SHA
    994e712 View commit details
    Browse the repository at this point in the history