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