diff --git a/CHANGELOG.md b/CHANGELOG.md index fcef9b5..7056cef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [2.0.0] [Unreleased] ### Changed -- Add `IfWatcher::poll_next`. Implement `Stream` instead of `Future` for `IfWatcher`. See [PR 23]. +- Add `IfWatcher::poll_if_event`. Implement `Stream` instead of `Future` for `IfWatcher`. + See [PR 23] and [PR 25]. - Make `IfWatcher::new` synchronous. See [PR 24]. [PR 23]: https://github.com/mxinden/if-watch/pull/23 [PR 24]: https://github.com/mxinden/if-watch/pull/24 +[PR 25]: https://github.com/mxinden/if-watch/pull/25 ## [1.1.1] diff --git a/src/apple.rs b/src/apple.rs index 060a728..f775058 100644 --- a/src/apple.rs +++ b/src/apple.rs @@ -59,7 +59,7 @@ impl IfWatcher { self.addrs.iter() } - pub fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { + pub fn poll_if_event(&mut self, cx: &mut Context) -> Poll> { loop { if let Some(event) = self.queue.pop_front() { return Poll::Ready(Ok(event)); diff --git a/src/fallback.rs b/src/fallback.rs index 0f76a30..c05ccdf 100644 --- a/src/fallback.rs +++ b/src/fallback.rs @@ -49,7 +49,7 @@ impl IfWatcher { self.addrs.iter() } - pub fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { + pub fn poll_if_event(&mut self, cx: &mut Context) -> Poll> { loop { if let Some(event) = self.queue.pop_front() { return Poll::Ready(Ok(event)); diff --git a/src/lib.rs b/src/lib.rs index 687c3a5..2067560 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,15 +66,15 @@ impl IfWatcher { } /// Poll for an address change event. - pub fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - Pin::new(&mut self.0).poll_next(cx) + pub fn poll_if_event(&mut self, cx: &mut Context) -> Poll> { + self.0.poll_if_event(cx) } } impl Stream for IfWatcher { type Item = Result; fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - self.poll_next(cx).map(Some) + Pin::into_inner(self).poll_if_event(cx).map(Some) } } diff --git a/src/linux.rs b/src/linux.rs index 85f31fa..0494c59 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -80,7 +80,7 @@ impl IfWatcher { } } - pub fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { + pub fn poll_if_event(&mut self, cx: &mut Context) -> Poll> { loop { if let Some(event) = self.queue.pop_front() { return Poll::Ready(Ok(event)); diff --git a/src/win.rs b/src/win.rs index 586dd54..d73f32b 100644 --- a/src/win.rs +++ b/src/win.rs @@ -5,7 +5,6 @@ use if_addrs::IfAddr; use std::collections::VecDeque; use std::ffi::c_void; use std::io::{Error, ErrorKind, Result}; -use std::pin::Pin; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::task::{Context, Poll}; @@ -68,7 +67,7 @@ impl IfWatcher { self.addrs.iter() } - pub fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { + pub fn poll_if_event(&mut self, cx: &mut Context) -> Poll> { loop { if let Some(event) = self.queue.pop_front() { return Poll::Ready(Ok(event));