1 use crate::Stream; 2 use std::pin::Pin; 3 use std::task::{Context, Poll}; 4 use tokio::signal::windows::{CtrlBreak, CtrlC}; 5 6 /// A wrapper around [`CtrlC`] that implements [`Stream`]. 7 /// 8 /// [`CtrlC`]: struct@tokio::signal::windows::CtrlC 9 /// [`Stream`]: trait@crate::Stream 10 #[derive(Debug)] 11 #[cfg_attr(docsrs, doc(cfg(all(windows, feature = "signal"))))] 12 pub struct CtrlCStream { 13 inner: CtrlC, 14 } 15 16 impl CtrlCStream { 17 /// Create a new `CtrlCStream`. new(interval: CtrlC) -> Self18 pub fn new(interval: CtrlC) -> Self { 19 Self { inner: interval } 20 } 21 22 /// Get back the inner `CtrlC`. into_inner(self) -> CtrlC23 pub fn into_inner(self) -> CtrlC { 24 self.inner 25 } 26 } 27 28 impl Stream for CtrlCStream { 29 type Item = (); 30 poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<()>>31 fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<()>> { 32 self.inner.poll_recv(cx) 33 } 34 } 35 36 impl AsRef<CtrlC> for CtrlCStream { as_ref(&self) -> &CtrlC37 fn as_ref(&self) -> &CtrlC { 38 &self.inner 39 } 40 } 41 42 impl AsMut<CtrlC> for CtrlCStream { as_mut(&mut self) -> &mut CtrlC43 fn as_mut(&mut self) -> &mut CtrlC { 44 &mut self.inner 45 } 46 } 47 48 /// A wrapper around [`CtrlBreak`] that implements [`Stream`]. 49 /// 50 /// [`CtrlBreak`]: struct@tokio::signal::windows::CtrlBreak 51 /// [`Stream`]: trait@crate::Stream 52 #[derive(Debug)] 53 #[cfg_attr(docsrs, doc(cfg(all(windows, feature = "signal"))))] 54 pub struct CtrlBreakStream { 55 inner: CtrlBreak, 56 } 57 58 impl CtrlBreakStream { 59 /// Create a new `CtrlBreakStream`. new(interval: CtrlBreak) -> Self60 pub fn new(interval: CtrlBreak) -> Self { 61 Self { inner: interval } 62 } 63 64 /// Get back the inner `CtrlBreak`. into_inner(self) -> CtrlBreak65 pub fn into_inner(self) -> CtrlBreak { 66 self.inner 67 } 68 } 69 70 impl Stream for CtrlBreakStream { 71 type Item = (); 72 poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<()>>73 fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<()>> { 74 self.inner.poll_recv(cx) 75 } 76 } 77 78 impl AsRef<CtrlBreak> for CtrlBreakStream { as_ref(&self) -> &CtrlBreak79 fn as_ref(&self) -> &CtrlBreak { 80 &self.inner 81 } 82 } 83 84 impl AsMut<CtrlBreak> for CtrlBreakStream { as_mut(&mut self) -> &mut CtrlBreak85 fn as_mut(&mut self) -> &mut CtrlBreak { 86 &mut self.inner 87 } 88 } 89