Skip to content

Commit 2fb1784

Browse files
committed
add FusedIterator impl for FlattenOk
1 parent 8421d27 commit 2fb1784

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/flatten_ok.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fmt;
1+
use std::{fmt, iter::FusedIterator};
22

33
pub fn flatten_ok<I, T, E>(iter: I) -> FlattenOk<I, T, E>
44
where
@@ -35,6 +35,8 @@ where
3535
if let Some(item) = inner.next() {
3636
return Some(Ok(item));
3737
} else {
38+
// This is necessary for the iterator to implement `FusedIterator`
39+
// with only the orginal iterator being fused.
3840
self.inner = None;
3941
}
4042
}
@@ -71,3 +73,11 @@ where
7173
.finish()
7274
}
7375
}
76+
77+
/// Only the iterator being flattened needs to implement [`FusedIterator`].
78+
impl<I, T, E> FusedIterator for FlattenOk<I, T, E>
79+
where
80+
I: FusedIterator<Item = Result<T, E>>,
81+
T: IntoIterator,
82+
{
83+
}

0 commit comments

Comments
 (0)