]> xenbits.xensource.com Git - xen-guest-agent.git/commitdiff
Apply a few select formatting fixes from fmt
authorYann Dirson <yann.dirson@vates.fr>
Wed, 10 Jan 2024 17:11:53 +0000 (18:11 +0100)
committerYann Dirson <yann.dirson@vates.fr>
Thu, 11 Jan 2024 10:43:00 +0000 (11:43 +0100)
Most of the rest mostly hampers readability.

Signed-off-by: Yann Dirson <yann.dirson@vates.fr>
12 files changed:
src/collector_memory.rs
src/collector_memory_linux.rs
src/collector_net.rs
src/collector_net_netlink.rs
src/collector_net_pnet.rs
src/datastructs.rs
src/main.rs
src/publisher.rs
src/vif_detect_freebsd.rs
src/vif_detect_linux.rs
src/xenstore_schema_rfc.rs
src/xenstore_schema_std.rs

index 0330fcedde91478a0022a1fdd478cb9bbadc3e1d..3800ddeeb8c891163349a55d131074c87356734b 100644 (file)
@@ -1,7 +1,6 @@
 use std::io;
 
-pub struct MemorySource {
-}
+pub struct MemorySource {}
 
 impl MemorySource {
     pub fn new() -> io::Result<MemorySource> {
index ce574994732b8e7ee542d10d1aa5abdc0dea866f..0a850be352f0e96aec1f7835b665fbbc60ea1149 100644 (file)
@@ -17,7 +17,7 @@ impl 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();
index a998dc2521bbbb2cb3f7e1980ce6ce9527c98e64..cd35e188ff2c218a0da93322bb54785ead711f0b 100644 (file)
@@ -3,8 +3,7 @@ use futures::stream::Stream;
 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> {
@@ -12,7 +11,7 @@ impl 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>> + '_ {
index 51ee497c9ce8530caed3e3d132993fde5f826866..96593919005632694fce7d2899cf8eea10d2c5d0 100644 (file)
@@ -1,28 +1,18 @@
-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;
index 5bc826b55a894e719a81e7b5e83ff08295f2afce..a503cab2ae53287904f38cc9fa235edac294bf46 100644 (file)
@@ -1,10 +1,10 @@
-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;
@@ -57,7 +57,6 @@ impl NetworkSource {
         }
     }
 
-
     fn get_ifconfig_data(&mut self) -> io::Result<Vec<NetEvent>> {
         let network_interfaces = pnet_datalink::interfaces();
 
@@ -80,7 +79,7 @@ impl NetworkSource {
         // 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();
 
@@ -102,7 +101,7 @@ impl NetworkSource {
                     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()),
index 2b8a96d6f4e2f2a989b898798802adb117de32da..67e759f725d12718df01b4f2c2c23f9bb5890893 100644 (file)
@@ -36,7 +36,7 @@ pub struct NetInterface {
 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
index 4ff675fabef9419f86670db167e7f31e69625a43..476d9b455303f58b613b6dc4de301a2178fccbe9 100644 (file)
@@ -3,9 +3,9 @@ mod datastructs;
 #[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")]
@@ -21,12 +21,12 @@ mod vif_detect;
 
 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;
index 247e9fc764aeb1d47a5d866ae25f35adb8e9fa28..2ebc2d9138b30d08c8a2292abf151f79c880cbc0 100644 (file)
@@ -4,8 +4,7 @@ use os_info;
 use std::error::Error;
 use std::io;
 
-pub struct Publisher {
-}
+pub struct Publisher {}
 
 impl Publisher {
     pub fn new() -> Result<Publisher, Box<dyn Error>> {
@@ -19,7 +18,7 @@ impl Publisher {
         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(())
index f1c90c9e683496bb529637795278178919a1082d..d3eb09e990a9a024f4232abe6ccced195f717faf 100644 (file)
@@ -4,7 +4,7 @@ use crate::datastructs::ToolstackNetInterface;
 
 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;
     }
index 7e0e6e9e8399e85d3f9952577956001db08ed99c..e1b9d7167c3dc33916afdf09f2c129b1f6be3c69 100644 (file)
@@ -20,7 +20,7 @@ pub fn get_toolstack_interface(iface_name: &str) -> ToolstackNetInterface {
                 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;
                     }
index 8c80245814641627082bae48353102f33e8847b4..a2509497422f374e51550d5ed1ac287be4839000 100644 (file)
@@ -1,5 +1,5 @@
 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;
index a4c2249a60d4c707c3f5f7967900deb25760655f..9598d3bb3a8edfb691baa67549fb380bdc22fe46 100644 (file)
@@ -1,5 +1,5 @@
 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;
@@ -76,7 +76,7 @@ impl XenstoreSchema for Schema {
             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