Most of the rest mostly hampers readability.
Signed-off-by: Yann Dirson <yann.dirson@vates.fr>
use std::io;
-pub struct MemorySource {
-}
+pub struct MemorySource {}
impl MemorySource {
pub fn new() -> io::Result<MemorySource> {
pub fn get_available_kb(&mut self) -> io::Result<usize> {
self.get_num_field("MemAvailable:")
}
-
+
fn get_num_field(&mut self, tag: &str) -> io::Result<usize> {
self.meminfo.rewind()?;
let mut rawdata = String::new();
use std::error::Error;
use std::io;
-pub struct NetworkSource {
-}
+pub struct NetworkSource {}
impl NetworkSource {
pub fn new(_cache: &'static mut NetInterfaceCache) -> io::Result<NetworkSource> {
}
pub async fn collect_current(&mut self) -> Result<Vec<NetEvent>, Box<dyn Error>> {
- Ok(vec!())
+ Ok(vec![])
}
pub fn stream(&mut self) -> impl Stream<Item = io::Result<NetEvent>> + '_ {
-use async_stream::try_stream;
use crate::datastructs::{NetEvent, NetEventOp, NetInterface, NetInterfaceCache};
+use async_stream::try_stream;
use futures::channel::mpsc::UnboundedReceiver;
use futures::stream::{Stream, StreamExt};
use netlink_packet_core::{
- NetlinkHeader,
- NetlinkMessage,
- NetlinkPayload,
- NLM_F_DUMP,
- NLM_F_REQUEST,
+ NetlinkHeader, NetlinkMessage, NetlinkPayload, NLM_F_DUMP, NLM_F_REQUEST,
};
use netlink_packet_route::{
- address::AddressMessage, address,
- link::LinkMessage, link,
- RouteNetlinkMessage,
+ address, address::AddressMessage, link, link::LinkMessage, RouteNetlinkMessage,
};
use netlink_proto::{
self, new_connection,
sys::{protocols::NETLINK_ROUTE, AsyncSocket, SocketAddr},
};
-use rtnetlink::constants::{
- RTMGRP_IPV4_IFADDR,
- RTMGRP_IPV6_IFADDR,
- RTMGRP_LINK,
- };
+use rtnetlink::constants::{RTMGRP_IPV4_IFADDR, RTMGRP_IPV6_IFADDR, RTMGRP_LINK};
use std::cell::RefCell;
use std::collections::hash_map;
use std::error::Error;
-use async_stream::try_stream;
use crate::datastructs::{NetEvent, NetEventOp, NetInterface, NetInterfaceCache};
+use async_stream::try_stream;
use futures::stream::Stream;
use ipnetwork::IpNetwork;
use pnet_base::MacAddr;
use std::cell::RefCell;
-use std::collections::{HashMap, HashSet, hash_map};
+use std::collections::{hash_map, HashMap, HashSet};
use std::error::Error;
use std::io;
use std::rc::Rc;
}
}
-
fn get_ifconfig_data(&mut self) -> io::Result<Vec<NetEvent>> {
let network_interfaces = pnet_datalink::interfaces();
// diff addresses_cache and current_addresses view
// events to be returned
- let mut events = vec!();
+ let mut events = vec![];
// pseudo-const to get a valid reference for unwrap_or
let empty_address_set: HashSet<Address> = HashSet::new();
let iface_adresses = &iface_info.addresses;
for disappearing in cached_info.addresses.difference(iface_adresses) {
log::trace!("disappearing {}: {:?}", iface.borrow().name, disappearing);
- events.push(NetEvent{
+ events.push(NetEvent {
iface: iface.clone(),
op: match disappearing {
Address::IP(ip) => NetEventOp::RmIp(ip.ip()),
impl NetInterface {
pub fn new(index: u32, name: Option<String>) -> NetInterface {
let name = match name {
- Some(string) => { string },
+ Some(string) => string,
None => {
log::error!("new interface with index {index} has no name");
String::from("") // this is not valid, but user will now be aware
#[cfg_attr(feature = "xenstore", path = "publisher_xenstore.rs")]
mod publisher;
#[cfg(feature = "xenstore")]
-mod xenstore_schema_std;
-#[cfg(feature = "xenstore")]
mod xenstore_schema_rfc;
+#[cfg(feature = "xenstore")]
+mod xenstore_schema_std;
#[cfg_attr(feature = "net_netlink", path = "collector_net_netlink.rs")]
#[cfg_attr(feature = "net_pnet", path = "collector_net_pnet.rs")]
use clap::Parser;
+use crate::collector_memory::MemorySource;
+use crate::collector_net::NetworkSource;
use crate::datastructs::KernelInfo;
use crate::publisher::Publisher;
-use crate::collector_net::NetworkSource;
-use crate::collector_memory::MemorySource;
-use futures::{FutureExt, pin_mut, select, TryStreamExt};
+use futures::{pin_mut, select, FutureExt, TryStreamExt};
use std::error::Error;
use std::io;
use std::str::FromStr;
use std::error::Error;
use std::io;
-pub struct Publisher {
-}
+pub struct Publisher {}
impl Publisher {
pub fn new() -> Result<Publisher, Box<dyn Error>> {
if let Some(mem_total_kb) = mem_total_kb {
println!("Total memory: {mem_total_kb} KB");
}
- if let Some(KernelInfo{release}) = kernel_info {
+ if let Some(KernelInfo { release }) = kernel_info {
println!("Kernel version: {}", release);
}
Ok(())
pub fn get_toolstack_interface(iface_name: &str) -> ToolstackNetInterface {
const PREFIX: &str = "xn";
- if ! iface_name.starts_with(PREFIX) {
+ if !iface_name.starts_with(PREFIX) {
log::debug!("ignoring interface {iface_name} as not starting with '{PREFIX}'");
return ToolstackNetInterface::None;
}
Ok(nodename) => {
let nodename = nodename.trim();
const PREFIX: &str = "device/vif/";
- if ! nodename.starts_with(PREFIX) {
+ if !nodename.starts_with(PREFIX) {
log::debug!("ignoring interface {nodename} as not under {PREFIX}");
return ToolstackNetInterface::None;
}
use crate::datastructs::{KernelInfo, NetEvent, NetEventOp};
-use crate::publisher::{XenstoreSchema, xs_publish, xs_unpublish};
+use crate::publisher::{xs_publish, xs_unpublish, XenstoreSchema};
use std::io;
use std::net::IpAddr;
use xenstore_rs::Xs;
use crate::datastructs::{KernelInfo, NetEvent, NetEventOp, NetInterface, ToolstackNetInterface};
-use crate::publisher::{XenstoreSchema, xs_publish, xs_unpublish};
+use crate::publisher::{xs_publish, xs_unpublish, XenstoreSchema};
use std::collections::HashMap;
use std::io;
use std::net::IpAddr;
xs_publish(&self.xs, "data/meminfo_total", &mem_total_kb.to_string())?;
}
- if ! self.forbidden_control_feature_balloon {
+ if !self.forbidden_control_feature_balloon {
// we may want to be more clever some day, e.g. by
// checking if the guest indeed has ballooning, and if the
// balloon driver has reached the requested initial