Skip to content

Commit

Permalink
*: Add IfWatcher::poll_if_event instead of IfWatcher::poll_next (#25
Browse files Browse the repository at this point in the history
)
  • Loading branch information
elenaf9 authored Aug 19, 2022
1 parent 137bd31 commit d876c4c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
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

0 comments on commit d876c4c

Please sign in to comment.