nmrs/lib.rs
1//! A Rust library for managing Wi-Fi connections via NetworkManager.
2//!
3//! This crate provides a high-level async API for common Wi-Fi operations:
4//!
5//! - Listing network devices and visible networks
6//! - Connecting to open, WPA-PSK, and WPA-EAP networks
7//! - Managing saved connection profiles
8//! - Enabling/disabling Wi-Fi
9//!
10//! # Example
11//!
12//! ```no_run
13//! use nmrs::{NetworkManager, WifiSecurity};
14//!
15//! # async fn example() -> nmrs::Result<()> {
16//! let nm = NetworkManager::new().await?;
17//!
18//! // List visible networks
19//! let networks = nm.list_networks().await?;
20//! for net in &networks {
21//! println!("{} ({}%)", net.ssid, net.strength.unwrap_or(0));
22//! }
23//!
24//! // Connect to a network
25//! nm.connect("MyNetwork", WifiSecurity::WpaPsk {
26//! psk: "password123".into()
27//! }).await?;
28//! # Ok(())
29//! # }
30//! ```
31//!
32//! # Error Handling
33//!
34//! All operations return `Result<T, ConnectionError>`. The error type provides
35//! specific variants for common failures like authentication errors, timeouts,
36//! and missing devices.
37
38// Internal implementation modules
39mod connection;
40mod connection_settings;
41mod constants;
42mod device;
43mod network_info;
44mod proxies;
45mod scan;
46mod state_wait;
47mod utils;
48
49// Public API modules
50pub mod models;
51pub mod network_manager;
52pub mod wifi_builders;
53
54// Re-exported public API
55pub use models::{
56 ConnectionError, ConnectionOptions, Device, DeviceState, DeviceType, EapMethod, EapOptions,
57 Network, NetworkInfo, Phase2, StateReason, WifiSecurity, reason_to_error,
58};
59pub use network_manager::NetworkManager;
60
61/// A specialized `Result` type for network operations.
62pub type Result<T> = std::result::Result<T, ConnectionError>;