X-Git-Url: https://code.octet-stream.net/netwatcher/blobdiff_plain/d2c9a9f306a336aa9dd8ddfb6579746e4f10b7a4..a26e228658fabc4495f3d671850903c8e105d9a1:/src/lib.rs?ds=inline diff --git a/src/lib.rs b/src/lib.rs index 5c8d73d..495b9e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,17 +4,24 @@ use std::{ ops::Sub, }; +mod error; + #[cfg_attr(windows, path = "list_win.rs")] #[cfg_attr(unix, path = "list_unix.rs")] mod list; #[cfg_attr(windows, path = "watch_win.rs")] #[cfg_attr(target_vendor = "apple", path = "watch_mac.rs")] -#[cfg_attr(target_os = "linux", path = "watch_linux.rs")] +#[cfg_attr( + any(target_os = "linux", target_os = "android"), + path = "watch_linux.rs" +)] mod watch; type IfIndex = u32; +pub use error::Error; + /// Information about one network interface at a point in time. #[derive(Debug, Clone, PartialEq, Eq)] pub struct Interface { @@ -68,13 +75,6 @@ pub struct InterfaceDiff { pub addrs_removed: Vec, } -/// Errors in netwatcher or in one of the underlying platform integratinos. -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum Error { - // TODO: handle all cases with proper sources - Internal, -} - #[derive(Default, PartialEq, Eq)] struct List(HashMap); @@ -145,6 +145,13 @@ pub fn list_interfaces() -> Result, Error> { /// /// The callback will fire once immediately with an initial interface list, and a diff as if /// there were originally no interfaces present. +/// +/// This function will return an error if there is a problem configuring the watcher, or if there +/// is an error retrieving the initial interface list. +/// +/// We assume that if listing the interfaces worked the first time, then it will continue to work +/// for as long as the watcher is running. If listing interfaces begins to fail later, those +/// failures will be swallowed and the callback will not be called for that change event. pub fn watch_interfaces( callback: F, ) -> Result {