]> git.lizzy.rs Git - rust.git/commit
Auto merge of #63177 - MOZGIII:find-result, r=Amanieu
authorbors <bors@rust-lang.org>
Thu, 2 Jan 2020 10:20:09 +0000 (10:20 +0000)
committerbors <bors@rust-lang.org>
Thu, 2 Jan 2020 10:20:09 +0000 (10:20 +0000)
commit0a58f5864659ddfe1d95c122abaa75c88220aed0
tree7b1e39ae2d96c2bb0cede5e9349136abf604d87d
parent766fba3fdca8fe075c370a63d2f76f8407483af5
parent5446cc99bb2a50bfed05bd781e9d72790a9ff570
Auto merge of #63177 - MOZGIII:find-result, r=Amanieu

Add Iterator::try_find

I found a need for this fn, and created this PR.

Tracking issue: #63178

I did a fair amount of thinking about the function name, and settled on the current one.
I don't see other anything else that's non-trivial here, but I'm open for debate. I just want this functionality to be there.
It couples with the `collect` trick for collecting `Result<Vec<T>, E>` from `Iterator<Item = Result<T, E>>`.

UPD:

I've already looked at `fallible_iterator` crate, but I don't think it supports my use case.
The main problem is that I can't construct a failable iterator. I have a regular iterator, and I just need to apply a predicate that can fail via `find` method.

UPD: `fallible_iterator` would work, but it's not elegant cause I'd have to make a failable iterator by mapping iterator with `Result::Ok` first.