Struct if_addrs::IfChangeNotifier

source ·
pub struct IfChangeNotifier { /* private fields */ }
Available on non-Apple or non-FreeBSD or non-NetBSD or non-OpenBSD only.
Expand description

(Not available on iOS/macOS) A utility to monitor for interface changes and report them, so you can handle events such as WiFi disconnection/flight mode/route changes

Implementations§

source§

impl IfChangeNotifier

source

pub fn new() -> Result<Self>

Create a new interface change notifier. Returns an OS specific error if the network notifier could not be set up.

Examples found in repository?
examples/detect_interface_changes.rs (line 5)
4
5
6
7
8
9
10
11
12
fn main() {
    let mut if_change_notifier = if_addrs::IfChangeNotifier::new().unwrap();
    println!("Waiting for interface changes...");
    loop {
        if let Ok(details) = if_change_notifier.wait(None) {
            println!("Network interfaces changed: {:#?}", details);
        }
    }
}
source

pub fn wait(&mut self, timeout: Option<Duration>) -> Result<Vec<IfChangeType>>

(Not available on iOS/macOS) Block until the OS reports that the network interface list has changed, or until an optional timeout.

For example, if an ethernet connector is plugged/unplugged, or a WiFi network is connected to.

The changed interfaces are returned. If an interface has both IPv4 and IPv6 addresses, you can expect both of them to be returned from a single call to wait.

Returns an [io::ErrorKind::WouldBlock] error on timeout, or another error if the network notifier could not be read from.

Examples found in repository?
examples/detect_interface_changes.rs (line 8)
4
5
6
7
8
9
10
11
12
fn main() {
    let mut if_change_notifier = if_addrs::IfChangeNotifier::new().unwrap();
    println!("Waiting for interface changes...");
    loop {
        if let Ok(details) = if_change_notifier.wait(None) {
            println!("Network interfaces changed: {:#?}", details);
        }
    }
}

Auto Trait Implementations§

§

impl Freeze for IfChangeNotifier

§

impl RefUnwindSafe for IfChangeNotifier

§

impl Send for IfChangeNotifier

§

impl Sync for IfChangeNotifier

§

impl Unpin for IfChangeNotifier

§

impl UnwindSafe for IfChangeNotifier

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.