Skip to content

add a trait for external iterator objects #5599

Closed
@thestinger

Description

@thestinger

There's currently an example of this in the treemap module, since it's required to set methods like intersection in-order. An external iterator is basically a state machine, so they're somewhat painful to write by hand but it's possible to generate them automatically, and that could be tackled at some point (probably post-1.0).

The only method the trait will require is fn next(&mut self) -> Option<T>. A default implementation a wrapper (see {map, set}_advance in treemap.rs) for integrating with for loops can be provided.

Unlike internal iteration that works with a closure, external iterators can be interleaved and keep their state when you break out of a loop. All iterators (forward, reverse, range within a container, counter, etc.) can implement the same interface, which means a generic library like Python's itertools can be written around them.

Blocking on #5598 for now, because this should be done with methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions