async_utils::fold

Function try_fold_while

Source
pub fn try_fold_while<S, T, D, F, Fut>(
    s: S,
    init: T,
    f: F,
) -> impl Future<Output = Result<FoldResult<T, D>, S::Error>>
where S: TryStream, F: FnMut(T, S::Ok) -> Fut, Fut: Future<Output = Result<FoldWhile<T, D>, S::Error>>,
Expand description

Similar to [TryStreamExt::try_fold], but the closure f can short-circuit the operation by returning FoldWhile::Done.

Returns FoldResult::StreamEnded with the current folded value when the stream ends. Returns FoldResult::ShortCircuited with the value of FoldWhile::Done if f short-circuits the operation. Returns Err if either s or f returns an error.