#[non_exhaustive]pub struct Device {
pub path: String,
pub interface: String,
pub identity: DeviceIdentity,
pub device_type: DeviceType,
pub state: DeviceState,
pub managed: Option<bool>,
pub driver: Option<String>,
pub ip4_address: Option<String>,
pub ip6_address: Option<String>,
pub frequency: Option<u32>,
pub speed_mbps: Option<u32>,
}Expand description
Represents a network device managed by NetworkManager.
A device can be a WiFi adapter, Ethernet interface, or other network hardware.
§Examples
use nmrs::NetworkManager;
let nm = NetworkManager::new().await?;
let devices = nm.list_devices().await?;
for device in devices {
println!("Interface: {}", device.interface);
println!(" Type: {}", device.device_type);
println!(" State: {}", device.state);
println!(" MAC: {}", device.identity.current_mac);
if device.is_wireless() {
println!(" This is a WiFi device");
} else if device.is_wired() {
println!(" This is an Ethernet device");
} else if device.is_bluetooth() {
println!(" This is a Bluetooth device");
} else if device.is_loopback() {
println!(" This is a loopback device");
}
if let Some(driver) = &device.driver {
println!(" Driver: {}", driver);
}
}Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.path: StringD-Bus object path
interface: StringInterface name (e.g., “wlan0”, “eth0”)
identity: DeviceIdentityDevice hardware identity (MAC addresses)
device_type: DeviceTypeType of device (WiFi, Ethernet, etc.)
state: DeviceStateCurrent device state
managed: Option<bool>Whether NetworkManager manages this device
driver: Option<String>Kernel driver name
ip4_address: Option<String>Assigned IPv4 address with CIDR notation (only present when connected)
ip6_address: Option<String>Assigned IPv6 address with CIDR notation (only present when connected)
frequency: Option<u32>Operating frequency in MHz for the active Wi-Fi connection, if known.
speed_mbps: Option<u32>Link speed in megabits per second for Ethernet devices, if known.
This is the raw value reported by NetworkManager. Some drivers report
0 when no carrier is present.
Implementations§
Source§impl Device
impl Device
Sourcepub fn is_wireless(&self) -> bool
pub fn is_wireless(&self) -> bool
Returns true if this is a wireless (Wi-Fi) device.
Sourcepub fn is_bluetooth(&self) -> bool
pub fn is_bluetooth(&self) -> bool
Returns ‘true’ if this is a Bluetooth (DUN or PANU) device.
Sourcepub fn is_loopback(&self) -> bool
pub fn is_loopback(&self) -> bool
Returns true if this is a loopback device (e.g., lo).