From 20d144456a070bec044786197e2a9b55fd9091fd Mon Sep 17 00:00:00 2001 From: elenaf9 Date: Sat, 13 Aug 2022 14:50:57 +0200 Subject: [PATCH 1/4] *: hide pinning internally --- src/apple.rs | 2 +- src/fallback.rs | 2 +- src/lib.rs | 4 ++-- src/linux.rs | 2 +- src/win.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/apple.rs b/src/apple.rs index 060a728..79d1293 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_next(&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..bc453de 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_next(&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..b8b75b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,7 +66,7 @@ impl IfWatcher { } /// Poll for an address change event. - pub fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { + pub fn poll_next(&mut self, cx: &mut Context) -> Poll> { Pin::new(&mut self.0).poll_next(cx) } } @@ -74,7 +74,7 @@ impl IfWatcher { 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_next(cx).map(Some) } } diff --git a/src/linux.rs b/src/linux.rs index 85f31fa..a2772e0 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_next(&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..bc0fd31 100644 --- a/src/win.rs +++ b/src/win.rs @@ -68,7 +68,7 @@ impl IfWatcher { self.addrs.iter() } - pub fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { + pub fn poll_next(&mut self, cx: &mut Context) -> Poll> { loop { if let Some(event) = self.queue.pop_front() { return Poll::Ready(Ok(event)); From 38ce06df22d51da479bd6b8c122e687a7e393656 Mon Sep 17 00:00:00 2001 From: elenaf9 Date: Sat, 13 Aug 2022 15:04:29 +0200 Subject: [PATCH 2/4] *: fix unnecessary pinning, unused import --- src/lib.rs | 2 +- src/win.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b8b75b6..bb0bd42 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,7 +67,7 @@ impl IfWatcher { /// Poll for an address change event. pub fn poll_next(&mut self, cx: &mut Context) -> Poll> { - Pin::new(&mut self.0).poll_next(cx) + self.0.poll_next(cx) } } diff --git a/src/win.rs b/src/win.rs index bc0fd31..69f49b8 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}; From e56e686317eec6b0e92f4c1c6a01df103fc88ff7 Mon Sep 17 00:00:00 2001 From: elenaf9 Date: Sat, 13 Aug 2022 15:05:34 +0200 Subject: [PATCH 3/4] *: rename `poll_next` -> `poll_if_event` --- src/apple.rs | 2 +- src/fallback.rs | 2 +- src/lib.rs | 6 +++--- src/linux.rs | 2 +- src/win.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/apple.rs b/src/apple.rs index 79d1293..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, 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 bc453de..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, 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 bb0bd42..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, cx: &mut Context) -> Poll> { - 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> { - Pin::into_inner(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 a2772e0..0494c59 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -80,7 +80,7 @@ impl IfWatcher { } } - pub fn poll_next(&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 69f49b8..d73f32b 100644 --- a/src/win.rs +++ b/src/win.rs @@ -67,7 +67,7 @@ impl IfWatcher { self.addrs.iter() } - pub fn poll_next(&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)); From 93ca54efa3d33ae8468ab040072b794222074bee Mon Sep 17 00:00:00 2001 From: elenaf9 Date: Thu, 18 Aug 2022 17:27:55 +0200 Subject: [PATCH 4/4] *: changelog entry --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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]