Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: Add IfWatcher::poll_if_event instead of IfWatcher::poll_next #25

Merged
merged 4 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion src/apple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl IfWatcher {
self.addrs.iter()
}

pub fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<IfEvent>> {
pub fn poll_if_event(&mut self, cx: &mut Context) -> Poll<Result<IfEvent>> {
loop {
if let Some(event) = self.queue.pop_front() {
return Poll::Ready(Ok(event));
Expand Down
2 changes: 1 addition & 1 deletion src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl IfWatcher {
self.addrs.iter()
}

pub fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<IfEvent>> {
pub fn poll_if_event(&mut self, cx: &mut Context) -> Poll<Result<IfEvent>> {
loop {
if let Some(event) = self.queue.pop_front() {
return Poll::Ready(Ok(event));
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Result<IfEvent>> {
Pin::new(&mut self.0).poll_next(cx)
pub fn poll_if_event(&mut self, cx: &mut Context) -> Poll<Result<IfEvent>> {
self.0.poll_if_event(cx)
}
}

impl Stream for IfWatcher {
type Item = Result<IfEvent>;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
self.poll_next(cx).map(Some)
Pin::into_inner(self).poll_if_event(cx).map(Some)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl IfWatcher {
}
}

pub fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<IfEvent>> {
pub fn poll_if_event(&mut self, cx: &mut Context) -> Poll<Result<IfEvent>> {
loop {
if let Some(event) = self.queue.pop_front() {
return Poll::Ready(Ok(event));
Expand Down
3 changes: 1 addition & 2 deletions src/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -68,7 +67,7 @@ impl IfWatcher {
self.addrs.iter()
}

pub fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<IfEvent>> {
pub fn poll_if_event(&mut self, cx: &mut Context) -> Poll<Result<IfEvent>> {
loop {
if let Some(event) = self.queue.pop_front() {
return Poll::Ready(Ok(event));
Expand Down