dbus-settings-bindings/networkmanager/src/config/ip4.rs

38 lines
790 B
Rust
Raw Normal View History

2022-01-11 16:02:29 -05:00
// SPDX-License-Identifier: MPL-2.0
use crate::interface::config::ip4::Ipv4ConfigProxy;
use std::{net::Ipv4Addr, ops::Deref};
use zbus::Result;
2022-01-21 11:12:35 -05:00
#[derive(Debug)]
2022-01-11 16:02:29 -05:00
pub struct Ipv4Config<'a>(Ipv4ConfigProxy<'a>);
impl<'a> Ipv4Config<'a> {
pub async fn addresses(&self) -> Result<Vec<Vec<Ipv4Addr>>> {
let addresses = self.0.addresses().await?;
Ok(addresses
.into_iter()
2022-02-08 14:10:28 -05:00
.map(|addresses| {
addresses
.into_iter()
.map(|addr| addr.swap_bytes())
.map(Ipv4Addr::from)
.collect()
})
2022-01-11 16:02:29 -05:00
.collect())
}
}
impl<'a> Deref for Ipv4Config<'a> {
type Target = Ipv4ConfigProxy<'a>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<'a> From<Ipv4ConfigProxy<'a>> for Ipv4Config<'a> {
fn from(config: Ipv4ConfigProxy<'a>) -> Self {
Ipv4Config(config)
}
}