Skip to content

inclusive version of StreamExt::take_while? #2994

@svix-jbrown

Description

@svix-jbrown

I'm working on a project that uses streams heavily, and one thing that comes up a lot a few times is consuming streams up to a certain limit (typically the total bytesize of items buffered so far). Originally I thought that StreamExt::take_while looked right, but it's exclusive, so it consumes one more item from the source stream than it ever yields (which absolutely makes sense given its definition and implementation). Because the user's predicate is called after an item has been consumed, I don't believe there's any way to build this on top of StreamExt::take_while.

I'm using rust-rdkafka's StreamConsumer in my actual project, in which consuming from the source stream has side-effects, which is why it's key that I not drop items after consuming them.

For now, I've just implemented this myself but it might be nice to have in StreamExt.

See a very similar upstream issue on Iterator at rust-lang/rust#62208

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