Skip to content

Implement FusedIterator for core::iter::StepBy #757

@mineichen

Description

@mineichen

Proposal

Problem statement

core::iter::StepBy doesn't implement core::iter::FusedIterator.

Motivating examples or use cases

StepBy should be fused whenever the underlying iterator is fused. This causes problems, because range-set-blaze has a trait SortedStarts, which can only be implemented on types which also implement FusedItarator... This prevents us from Implementing SortedStarts for StepBy (which would always be valid, if the inner Iterator implements SortedStarts).

Solution sketch

impl<I: FusedIterator> FusedIterator for StepBy<I> {}

This is correct, as https://github.com/rust-lang/rust/blob/main/library/core/src/iter/adapters/step_by.rs on line 226 calls self.iter.nth(step_size) which is oke to be called after receiving None, if the inner iterator is Fused.

Alternatives

I don't consider it a alternative to always implement FusedIterator on StepBy without a FusedItarator trait bound, as it wouldn't be zero cost to implement this.

Links and related work

internals.rust-lang.org discussion

Metadata

Metadata

Assignees

No one assigned

    Labels

    ACP-acceptedAPI Change Proposal is accepted (seconded with no objections)T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard libraries

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions