netwatch-rs 0.2.0

A modern network traffic monitor for Unix systems, inspired by nload but written in Rust
Documentation
use crate::{device::NetworkReader, error::Result};

#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
pub use linux::LinuxReader;

#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "macos")]
pub use macos::MacOSReader;

pub fn create_reader() -> Result<Box<dyn NetworkReader>> {
    #[cfg(target_os = "linux")]
    return Ok(Box::new(LinuxReader::new()));

    #[cfg(target_os = "macos")]
    return Ok(Box::new(MacOSReader::new()));

    #[cfg(not(any(target_os = "linux", target_os = "macos")))]
    return Err(crate::error::NetwatchError::Platform(
        "Unsupported platform".to_string(),
    ));
}