Skip to content

Commit

Permalink
from review: add a comment why try_fold was chosen instead of fold
Browse files Browse the repository at this point in the history
  • Loading branch information
the8472 committed Jul 26, 2021
1 parent e015e9d commit 2276c5e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions library/core/src/array/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ impl<T, const N: usize> Iterator for IntoIter<T, N> {
Fold: FnMut(Acc, Self::Item) -> Acc,
{
let data = &mut self.data;
// FIXME: This uses try_fold(&mut iter) instead of fold(iter) because the latter
// would go through the blanket `impl Iterator for &mut I` implementation
// which lacks inline annotations on its methods and adding those would be a larger
// perturbation than using try_fold here.
// Whether it would be beneficial to add those annotations should be investigated separately.
(&mut self.alive)
.try_fold::<_, _, Result<_, !>>(init, |acc, idx| {
// SAFETY: idx is obtained by folding over the `alive` range, which implies the
Expand Down

0 comments on commit 2276c5e

Please sign in to comment.