Skip to content

Commit af424c1

Browse files
committed
Implement SourceIterator and InPlaceIterable for ResultShunt
1 parent fee0d31 commit af424c1

File tree

1 file changed

+23
-0
lines changed
  • library/core/src/iter/adapters

1 file changed

+23
-0
lines changed

library/core/src/iter/adapters/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,26 @@ where
191191
self.try_fold(init, ok(fold)).unwrap()
192192
}
193193
}
194+
195+
#[unstable(issue = "none", feature = "inplace_iteration")]
196+
unsafe impl<S: Iterator, I, E> SourceIter for ResultShunt<'_, I, E>
197+
where
198+
I: SourceIter<Source = S>,
199+
{
200+
type Source = S;
201+
202+
#[inline]
203+
unsafe fn as_inner(&mut self) -> &mut S {
204+
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
205+
unsafe { SourceIter::as_inner(&mut self.iter) }
206+
}
207+
}
208+
209+
// SAFETY: ResultShunt::next calls I::find, which has to advance `iter` in order to
210+
// return `Some(_)`. Since `iter` has type `I: InPlaceIterable` it's guaranteed that
211+
// at least one item will be moved out from the underlying source.
212+
#[unstable(issue = "none", feature = "inplace_iteration")]
213+
unsafe impl<I, T, E> InPlaceIterable for ResultShunt<'_, I, E> where
214+
I: Iterator<Item = Result<T, E>> + InPlaceIterable
215+
{
216+
}

0 commit comments

Comments
 (0)