diff --git a/src/action.rs b/src/action.rs index 840561cf88ea6d2ae3a6d7279855d0fa7000f167..d8edbe4a16a2c360af2d9f65f03f77b19f0c5e7d 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 ec7f3693fc5a7a41ee96b7f9161a322d237eecc7..810e1d2375b81f972922ae74470cdd2c1ef29b25 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 abd21fa5d5601705b0543c4399a637915a65f67c..74daf9b72a912858fa648c3388096b62d689e5a3 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 43a2b8aed8eedf1752e7a78d8d8dfc86e0dd33c9..3f8f7f01095637d5c4dc9d2dedabce24ede6317f 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 05dcee96d0d44a6cc510ea07ef556bb48b685f12..1b4f26d199d3672dbc72c0cd6dc89f3ccec93162 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 823429addb10625dedc73e295523ae9b3ef9f669..d0bf04472103b54344742cc062318a2f0d8c402c 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 7d3db2170d12df4e3531993a729a80ecc68ccc5a..56297b6da13fc372ef2101e935660653fa0aa0ca 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 65a2109db08fd6322f4b67865d204096c39ed03b..baae3fd810a0951ad312a6f1b2e788773e5671eb 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(()); }