Nmrs 3.5.12 release - a typed, async Rust library for NetworkManager

2026-11-12来源 Rust Users ForumEnglish

nmrs makes it easier to write GUIs, network applications, system utilities and other programs in Rust, without writing heavy boilerplate zbus/dbus code.

It's currently being shipped in Pop!_OS' Linux distribution via cosmic-settings and their experimental cosmic-applets among other consumers.

To best demonstrate its use, compare the following implementations of scanning and listing available Wi-Fi networks and displaying them in nmrs, and non-blocking D-Bus, respectively.

use nmrs::{NetworkManager, WifiSecurity}; #[tokio::main] async fn main() -> nmrs::Result<()> { let nm = NetworkManager::new().await?; // List networks let networks = nm.list_networks(None).await?; for net in &networks { println!("{} - Signal: {}%", net.ssid, net.strength.unwrap_or(0)); } // Connect to WPA-PSK network nm.connect("MyNetwork", None, WifiSecurity::WpaPsk { psk: "password".into() }).await?; // Check current connection if let Some(ssid) = nm.current_ssid().await { println!("Connected to: {}", ssid); } Ok(()) } 

D-Bus version:

A note: to be fair, the zbus version is probably much shorter, since its #[proxy] macro generates typed methods and properties for each interface. But you'd still be declaring those proxies, building the nested settings dictionaries by hand and walking devices and access points yourself, which is the part nmrs takes off your hands.

It supports Wi-Fi scanning and connections (open, WPA/WPA2/WPA3 Personal, and WPA/WPA3 Enterprise networks), Ethernet and VLAN management, Bluetooth network connections, WireGuard and OpenVPN VPNs, importing WireGuard .conf and OpenVPN .ovpn profiles, creating and managing saved NetworkManager connection profiles, device and network state monitoring, radio controls (Wi-Fi, WWAN, Bluetooth and airplane mode), internet connectivity and captive portal detection, global DNS configuration, real-time D-Bus event notifications, NetworkManager Secret Agent integration for handling credentials, and a fully asynchronous, strongly typed Rust API for interacting with NetworkManager without invoking a sub-process for nmcli or the likes.

Hope this is useful to someone. Thanks!

1 post - 1 participant

Read full topic

原文:https://www.a8q9.cn/en/article/nmrs-3-5-12-release-a-typed-async-rust-library-for-networkmanager-24a1ea.html

相关文章