fn collect_result<T, E>(mut it: impl ExactSizeIterator<Item = Result<T, E>>) -> Result<Vec<T>, E> {
    match it.next() {
        None => Ok(Vec::new()),
        Some(Err(e)) => Err(e),
        Some(Ok(x)) => {
            // +1 for the element we have already consumed
            let mut res = Vec::with_capacity(it.len() + 1);
            res.push(x);
            for x in it {
                res.push(x?);
            }
            Ok(res)
        }
    }
}
/// Optimised collect iterator into Vec, which might be a Result.
///
/// If we do a standard .collect() on the iterator it will never have a good size hint,
/// as the lower bound will always be zero, so might reallocate several times.
/// We know the Vec will either be thrown away, or exactly `len`, so aim if we do allocate,
/// make sure it is at `len`. However, if the first element throws an error, we don't need
/// to allocate at all, so special case that.
Optimised collect iterator into Vec, which might be a Result.
If we do a standard .collect() on the iterator it will never have a good size hint,
as the lower bound will always be zero, so might reallocate several times.
We know the Vec will either be thrown away, or exactly `len`, so aim if we do allocate,
make sure it is at `len`. However, if the first element throws an error, we don't need
to allocate at all, so special case that.
Optimised collect iterator into Vec which might be a Result . If we do a standard . collect () on the iterator it will never have a good size hint as the lower bound will always be zero so might reallocate several times . We know the Vec will either be thrown away or exactly ` len ` so aim if we do allocate make sure it is at ` len ` . However if the first element throws an error we don ' t need to allocate at all so special case that .
fn collect_result<T, E>(mut it: impl ExactSizeIterator<Item = Result<T, E>>) -> Result<Vec<T>, E> {
    match it.next() {
        None => Ok(Vec::new()),
        Some(Err(e)) => Err(e),
        Some(Ok(x)) => {
            // +1 for the element we have already consumed
            let mut res = Vec::with_capacity(it.len() + 1);
            res.push(x);
            for x in it {
                res.push(x?);
            }
            Ok(res)
        }
    }
}
fn collect_result < T , E > ( mut it : impl ExactSizeIterator < Item = Result < T , E > > ) -> Result < Vec < T > , E > { match it . next ( ) { None => Ok ( Vec :: new ( ) ) , Some ( Err ( e ) ) => Err ( e ) , Some ( Ok ( x ) ) => { // +1 for the element we have already consumed let mut res = Vec :: with_capacity ( it . len ( ) + 1 ) ; res . push ( x ) ; for x in it { res . push ( x ? ) ; } Ok ( res ) } } }
Optimised collect iterator into Vec, which might be a Result.
Optimised collect iterator into Vec which might be a Result .
it
impl ExactSizeIterator<Item = Result<T, E>>
it
impl ExactSizeIterator<Item = Result<T, E>>