1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use std::pin::Pin;
use crate::NextValue;
pin_project_lite::pin_project! {
pub struct IterHook<H> {
#[pin]
hook: H,
}
}
impl<H> IterHook<H> {
#[inline]
pub fn new(hook: H) -> Self {
Self { hook }
}
#[inline]
pub fn into_inner(self) -> H {
self.hook
}
#[inline]
pub fn pin_project_hook(self: Pin<&mut Self>) -> Pin<&mut H> {
self.project().hook
}
#[inline]
pub fn next_value(&mut self) -> NextValue<H, ()>
where
Self: Unpin,
{
NextValue::new(Pin::new(self).pin_project_hook(), ())
}
}
#[cfg(feature = "futures-core")]
impl<H> futures_core::Stream for IterHook<H>
where
H: crate::NonLendingHook<()>,
{
type Item = H::NonGenericValue;
#[inline]
fn poll_next(
self: Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Option<Self::Item>> {
let mut hook = self.pin_project_hook();
<H as crate::HookPollNextUpdate>::poll_next_update(hook.as_mut(), cx).map(|dynamic| {
if dynamic {
let value = <H as crate::Hook<()>>::use_hook(hook, ());
Some(value)
} else {
None
}
})
}
}