dbus-settings-bindings/networkmanager/src/nm.rs

29 lines
717 B
Rust
Raw Normal View History

2022-01-11 15:23:09 -05:00
// SPDX-License-Identifier: MPL-2.0
use crate::{
device::Device,
interface::{device::DeviceProxy, NetworkManagerProxy},
};
use zbus::{Connection, Result};
pub struct NetworkManager<'a>(NetworkManagerProxy<'a>);
impl<'a> NetworkManager<'a> {
pub async fn new(connection: &'a Connection) -> Result<NetworkManager<'a>> {
NetworkManagerProxy::new(connection).await.map(Self)
}
pub async fn devices(&self) -> Result<Vec<Device<'a>>> {
let devices = self.0.get_all_devices().await?;
let mut out = Vec::with_capacity(devices.len());
for device in devices {
let device = DeviceProxy::builder(self.0.connection())
.path(device)?
.build()
.await?;
out.push(device.into());
}
Ok(out)
}
}