A possibility you could consider is this (ResultShunt
-inspired) sketch I made a while ago: https://play.rust-lang.org/?version=nightly&edition=2018&gist=819dd12076a2a7add7cfd8733b8b03bd
That uses extend
, but could be tweaked to just take a different error handler closure. Then it'd still be lazy, one-pass, and non-allocating, with the "normal" iterator route dealing with the Ok
s and the slightly-out-of-band closure dealing with the Err
s as they show up.