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
60
61
62
63
64
65
66
use std::{pin::Pin, task::Poll};

use crate::{Hook, HookPollNextUpdate, HookValue};

use super::NextUpdate;

/// Extend [`HookPollNextUpdate`] with convenient methods.
pub trait HookPollNextUpdateExt: HookPollNextUpdate {
    /// A shortcut to call [`HookPollNextUpdate::poll_next_update`] on Unpin hooks.
    #[inline]
    fn poll_next_update(&mut self, cx: &mut std::task::Context<'_>) -> Poll<bool>
    where
        Self: Unpin,
    {
        HookPollNextUpdate::poll_next_update(Pin::new(self), cx)
    }

    /// Get a future which polls [`HookPollNextUpdate::poll_next_update`].
    #[inline]
    fn next_update(&mut self) -> NextUpdate<'_, Self>
    where
        Self: Unpin,
    {
        NextUpdate::new(self)
    }
}

impl<H: HookPollNextUpdate + ?Sized> HookPollNextUpdateExt for H {}

/// Extend [`Hook`](trait@Hook) with convenient methods.
pub trait HookExt: Hook {
    /// A shortcut to call [`Hook::use_hook`] on Unpin hooks.
    #[inline(always)]
    fn use_hook(&mut self) -> <Self as HookValue<'_>>::Value
    where
        Self: Unpin,
    {
        <Self as Hook>::use_hook(Pin::new(self))
    }

    #[inline]
    fn next_value(&mut self) -> super::NextValue<'_, Self>
    where
        Self: Unpin,
    {
        crate::NextValue::new(Pin::new(self))
    }

    #[inline]
    fn into_values(self) -> super::Values<Self>
    where
        Self: Sized,
    {
        super::Values::new(self)
    }

    #[inline]
    fn values(&mut self) -> super::Values<&mut Self>
    where
        Self: Unpin,
    {
        super::Values::new(self)
    }
}

impl<H: Hook + ?Sized> HookExt for H {}