We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 31fb3d4 commit f66cbbdCopy full SHA for f66cbbd
src/lib.rs
@@ -147,15 +147,11 @@ pub trait FallibleIterator {
147
148
/// Returns the last element of the iterator.
149
#[inline]
150
- fn last(mut self) -> Result<Option<Self::Item>, Self::Error>
+ fn last(self) -> Result<Option<Self::Item>, Self::Error>
151
where
152
Self: Sized,
153
{
154
- let mut last = None;
155
- while let Some(e) = self.next()? {
156
- last = Some(e);
157
- }
158
- Ok(last)
+ self.fold(None, |_, v| Ok(Some(v)))
159
}
160
161
/// Returns the `n`th element of the iterator.
0 commit comments