summaryrefslogtreecommitdiffstats
path: root/third_party/rust/tokio-stream/src/wrappers/signal_windows.rs
blob: 4631fbad8dc26685ca482ef021c8e1eeda3de578 (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use crate::Stream;
use std::pin::Pin;
use std::task::{Context, Poll};
use tokio::signal::windows::{CtrlBreak, CtrlC};

/// A wrapper around [`CtrlC`] that implements [`Stream`].
///
/// [`CtrlC`]: struct@tokio::signal::windows::CtrlC
/// [`Stream`]: trait@crate::Stream
#[derive(Debug)]
#[cfg_attr(docsrs, doc(cfg(all(windows, feature = "signal"))))]
pub struct CtrlCStream {
    inner: CtrlC,
}

impl CtrlCStream {
    /// Create a new `CtrlCStream`.
    pub fn new(interval: CtrlC) -> Self {
        Self { inner: interval }
    }

    /// Get back the inner `CtrlC`.
    pub fn into_inner(self) -> CtrlC {
        self.inner
    }
}

impl Stream for CtrlCStream {
    type Item = ();

    fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<()>> {
        self.inner.poll_recv(cx)
    }
}

impl AsRef<CtrlC> for CtrlCStream {
    fn as_ref(&self) -> &CtrlC {
        &self.inner
    }
}

impl AsMut<CtrlC> for CtrlCStream {
    fn as_mut(&mut self) -> &mut CtrlC {
        &mut self.inner
    }
}

/// A wrapper around [`CtrlBreak`] that implements [`Stream`].
///
/// [`CtrlBreak`]: struct@tokio::signal::windows::CtrlBreak
/// [`Stream`]: trait@crate::Stream
#[derive(Debug)]
#[cfg_attr(docsrs, doc(cfg(all(windows, feature = "signal"))))]
pub struct CtrlBreakStream {
    inner: CtrlBreak,
}

impl CtrlBreakStream {
    /// Create a new `CtrlBreakStream`.
    pub fn new(interval: CtrlBreak) -> Self {
        Self { inner: interval }
    }

    /// Get back the inner `CtrlBreak`.
    pub fn into_inner(self) -> CtrlBreak {
        self.inner
    }
}

impl Stream for CtrlBreakStream {
    type Item = ();

    fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<()>> {
        self.inner.poll_recv(cx)
    }
}

impl AsRef<CtrlBreak> for CtrlBreakStream {
    fn as_ref(&self) -> &CtrlBreak {
        &self.inner
    }
}

impl AsMut<CtrlBreak> for CtrlBreakStream {
    fn as_mut(&mut self) -> &mut CtrlBreak {
        &mut self.inner
    }
}