Skip to content

Consider offering try_next() -> Result<Option<T>> for our stream-like things #5671

@dbolduc

Description

@dbolduc

Our stream-like things all have a next() (or maybe poll()) method which return an Option<Result<T>>.

So often example code looks like:

let mut stream = ...;
while let Some(item) = stream.next().await.transpose()? {
  println!("item={item:?}");
}

To slightly improve application ergonomics, we could consider offering a try_next() for our streams as a shorthand for omitting the transpose() (akin to futures::TryStreamExt)

let mut stream = ...;
while let Some(item) = stream.try_next().await? {
  println!("item={item:?}");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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