From 57190ddfa6b04ba00e3d754957b3ece40cfdbb62 Mon Sep 17 00:00:00 2001 From: Eduardo Trujillo <ed@chromabits.com> Date: Sun, 2 Jan 2022 14:34:46 -0800 Subject: [PATCH] Clean up linter warnings --- src/action.rs | 7 +++---- src/condition.rs | 6 +++--- src/config.rs | 10 +--------- src/dbus_wrappers/device.rs | 2 +- src/dbus_wrappers/manager.rs | 10 ++-------- src/identifier.rs | 4 ++-- src/main.rs | 2 +- src/rule.rs | 4 ++-- 8 files changed, 15 insertions(+), 30 deletions(-) diff --git a/src/action.rs b/src/action.rs index 840561c..d8edbe4 100644 --- a/src/action.rs +++ b/src/action.rs @@ -73,10 +73,9 @@ impl Action { .activate_connection( maybe_connection.as_ref(), maybe_device.as_ref(), - match specific_object { - Some(inner) => Some(Path::from(inner.clone())), - None => None, - }, + specific_object + .as_ref() + .map(|inner| Path::from(inner.clone())), ) .await?; diff --git a/src/condition.rs b/src/condition.rs index ec7f369..810e1d2 100644 --- a/src/condition.rs +++ b/src/condition.rs @@ -170,14 +170,14 @@ async fn device_matches_states( } } -async fn device_is_connected_to_one_of<'a>( +async fn device_is_connected_to_one_of( conn: &Arc<SyncConnection>, device_identifier: &DeviceIdentifier, - connections: &'a Vec<ActiveConnectionIdentifier>, + connections: &[ActiveConnectionIdentifier], ) -> Result<bool> { match device_identifier.into_device(conn).await? { Some(device) => { - let active_connections: Vec<ActiveConnectionWrapper<'a>> = stream::iter(connections) + let active_connections: Vec<ActiveConnectionWrapper> = stream::iter(connections) .filter_map(|connection_identifier| async move { match connection_identifier.into_active_connection(conn).await { Ok(active_connection) => active_connection, diff --git a/src/config.rs b/src/config.rs index abd21fa..74daf9b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,18 +2,10 @@ use serde_derive::{Deserialize, Serialize}; use crate::rule::Rule; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Default)] pub struct Config { // Rules to evaluate when processing events. // // Rules are evaluated serially in the order provided. pub rules: Vec<Rule> -} - -impl Default for Config { - fn default() -> Self { - Config { - rules: vec![] - } - } } \ No newline at end of file diff --git a/src/dbus_wrappers/device.rs b/src/dbus_wrappers/device.rs index 43a2b8a..3f8f7f0 100644 --- a/src/dbus_wrappers/device.rs +++ b/src/dbus_wrappers/device.rs @@ -37,7 +37,7 @@ impl<'a> DeviceWrapper<'a> { ); DeviceWrapper { - conn: conn.clone(), + conn, proxy: Box::new(proxy), path, } diff --git a/src/dbus_wrappers/manager.rs b/src/dbus_wrappers/manager.rs index 05dcee9..1b4f26d 100644 --- a/src/dbus_wrappers/manager.rs +++ b/src/dbus_wrappers/manager.rs @@ -15,7 +15,7 @@ use crate::dbus_codegen::network_manager::{ use super::{active_connection::ActiveConnectionWrapper, connection::ConnectionWrapper, connectivity_state::ConnectivityState, device::DeviceWrapper, signal::SignalStreamWrapper, state::State}; -const PATH: &'static str = "/org/freedesktop/NetworkManager"; +const PATH: &str = "/org/freedesktop/NetworkManager"; pub struct ManagerWrapper<'a> { conn: Arc<SyncConnection>, @@ -45,12 +45,6 @@ impl<'a> ManagerWrapper<'a> { Ok(device_path) } - pub async fn get_device_by_ip_iface(&self, iface: &str) -> anyhow::Result<DeviceWrapper<'_>> { - let device_path = self.get_device_path_by_ip_iface(iface).await?; - - Ok(DeviceWrapper::from_path(self.conn.clone(), device_path.clone()).await) - } - pub async fn get_all_device_paths(&self) -> anyhow::Result<Vec<Path<'a>>> { let device_paths = self.inner.get_all_devices().await?; @@ -124,7 +118,7 @@ impl<'a> ManagerWrapper<'a> { .activate_connection( connection.map_or(Path::from("/"), |c| c.get_path()), device.map_or(Path::from("/"), |d| d.get_path()), - specific_object.unwrap_or(Path::from("/")), + specific_object.unwrap_or_else(|| Path::from("/")), ) .await?; diff --git a/src/identifier.rs b/src/identifier.rs index 823429a..d0bf044 100644 --- a/src/identifier.rs +++ b/src/identifier.rs @@ -96,7 +96,7 @@ impl ActiveConnectionIdentifier { ActiveConnectionIdentifier::ConnectionUUID { connection_uuid } => { let manager = ManagerWrapper::from_connection(conn).await; let active_connection = manager - .get_active_connection_from_uuid(&connection_uuid) + .get_active_connection_from_uuid(connection_uuid) .await?; Ok(active_connection) @@ -110,7 +110,7 @@ impl ActiveConnectionIdentifier { ActiveConnectionIdentifier::DeviceInterface { device_interface } => { let manager = ManagerWrapper::from_connection(conn).await; let device_path = manager - .get_device_path_by_ip_iface(&device_interface) + .get_device_path_by_ip_iface(device_interface) .await?; let device = DeviceWrapper::from_path(conn.clone(), device_path).await; diff --git a/src/main.rs b/src/main.rs index 7d3db21..56297b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,7 +62,7 @@ impl ConfigurableAppOpts<config::Config> for Opts { } async fn inner_main() -> anyhow::Result<()> { - let (opts, config) = Opts::try_init_with_config()?; + let (_opts, config) = Opts::try_init_with_config()?; let config = Arc::new(config); log::info!("Parsed config and {} rules", config.rules.len()); diff --git a/src/rule.rs b/src/rule.rs index 65a2109..baae3fd 100644 --- a/src/rule.rs +++ b/src/rule.rs @@ -43,7 +43,7 @@ impl Rule { }) .await; - if any_trigger_matches == false { + if !any_trigger_matches { return Ok(()); } @@ -60,7 +60,7 @@ impl Rule { }) .await; - if all_conditions_pass == false { + if !all_conditions_pass { return Ok(()); } -- GitLab