core/iter/sources/
from_coroutine.rs
1use crate::fmt;
2use crate::ops::{Coroutine, CoroutineState};
3use crate::pin::Pin;
4
5#[inline]
26#[unstable(feature = "iter_from_coroutine", issue = "43122", reason = "coroutines are unstable")]
27pub fn from_coroutine<G: Coroutine<Return = ()> + Unpin>(coroutine: G) -> FromCoroutine<G> {
28 FromCoroutine(coroutine)
29}
30
31#[unstable(feature = "iter_from_coroutine", issue = "43122", reason = "coroutines are unstable")]
38#[derive(Clone)]
39pub struct FromCoroutine<G>(G);
40
41#[unstable(feature = "iter_from_coroutine", issue = "43122", reason = "coroutines are unstable")]
42impl<G: Coroutine<Return = ()> + Unpin> Iterator for FromCoroutine<G> {
43 type Item = G::Yield;
44
45 fn next(&mut self) -> Option<Self::Item> {
46 match Pin::new(&mut self.0).resume(()) {
47 CoroutineState::Yielded(n) => Some(n),
48 CoroutineState::Complete(()) => None,
49 }
50 }
51}
52
53#[unstable(feature = "iter_from_coroutine", issue = "43122", reason = "coroutines are unstable")]
54impl<G> fmt::Debug for FromCoroutine<G> {
55 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56 f.debug_struct("FromCoroutine").finish()
57 }
58}