Work on more Rust-side bindings

This commit is contained in:
Lucy 2022-01-11 16:02:29 -05:00
parent 91a7fc6da1
commit da5c6ed172
No known key found for this signature in database
GPG key ID: EBC517FAD666BBF1
7 changed files with 116 additions and 2 deletions

View file

@ -0,0 +1,30 @@
// SPDX-License-Identifier: MPL-2.0
use crate::interface::config::ip4::Ipv4ConfigProxy;
use std::{net::Ipv4Addr, ops::Deref};
use zbus::Result;
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()
.map(|addresses| addresses.into_iter().map(Ipv4Addr::from).collect())
.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)
}
}

View file

@ -0,0 +1,35 @@
// SPDX-License-Identifier: MPL-2.0
use crate::interface::config::ip6::Ipv6ConfigProxy;
use std::{net::Ipv6Addr, ops::Deref};
use zbus::Result;
pub struct Ipv6Config<'a>(Ipv6ConfigProxy<'a>);
impl<'a> Ipv6Config<'a> {
pub async fn addresses(&self) -> Result<Vec<Ipv6Addr>> {
let addresses = self.0.addresses().await?;
Ok(addresses
.into_iter()
.map(|(address, _, _)| {
let address_bytes: [u8; 16] = address
.try_into()
.expect("NetworkManager gave invalid IPv6 addresss");
Ipv6Addr::from(address_bytes)
})
.collect())
}
}
impl<'a> Deref for Ipv6Config<'a> {
type Target = Ipv6ConfigProxy<'a>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<'a> From<Ipv6ConfigProxy<'a>> for Ipv6Config<'a> {
fn from(config: Ipv6ConfigProxy<'a>) -> Self {
Ipv6Config(config)
}
}