Skip to content

Should TryStream::try_filter accept closures that return Results? #2375

@mythmon

Description

@mythmon

I expected to be able to be able to filter a try stream with a fallible filter function, like this:

try_stream.try_filter(|v| v.fallible_async_operation().await?)

However, try_filter expects the closure passed to return simply a boolean. The try_ in try_filter allows it to skip Errors that are already in the stream. This seems like a gap of useful functionality.

As a work around I've done something like this

try_stream.try_filter_map(|v|
	if v.fallible_async_operation().await? {
		Ok(Some(v))
	} else {
		Ok(None)
	}
)

I would have expected both try_filter and try_filter_map to handle fallible filters.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions