/// Folds its contents to a result. pub trait FoldResult: Sized { type Item; /// Processes all contained items returning the last successful result or the first error. /// If there are no items, returns `Ok(R::default())`. fn fold_defresult(self, func: F) -> Result where R: Default, F: FnMut(Self::Item) -> Result { self.fold_result(R::default(), func) } /// Processes all contained items returning the last successful result or the first error. /// If there are no items, returns `Ok(default)`. fn fold_result(self, default: R, mut func: F) -> Result where F: FnMut(Self::Item) -> Result; } impl> FoldResult for I { type Item = X; fn fold_result(self, default: R, mut func: F) -> Result where F: FnMut(Self::Item) -> Result { self.fold(Ok(default), |acc, item| acc.and_then(|_| func(item))) } }