From 10cbdb1e001e199ba64b85e0f628f7255feda5cf Mon Sep 17 00:00:00 2001 From: Orne Brocaar Date: Mon, 14 Oct 2024 14:46:22 +0100 Subject: [PATCH] Fix clippy feedback. --- chirpstack/src/api/internal.rs | 3 +-- chirpstack/src/api/tenant.rs | 2 +- chirpstack/src/api/user.rs | 2 +- chirpstack/src/cmd/configfile.rs | 1 + .../src/cmd/import_lorawan_device_profiles.rs | 18 ++++++++---------- chirpstack/src/downlink/data.rs | 8 ++++---- chirpstack/src/downlink/error.rs | 4 ++-- chirpstack/src/storage/device.rs | 7 ++----- chirpstack/src/storage/fields/big_decimal.rs | 2 +- chirpstack/src/storage/fields/dev_nonces.rs | 8 ++------ .../src/storage/fields/device_session.rs | 6 +++--- chirpstack/src/storage/fields/uuid.rs | 10 +++++----- chirpstack/src/storage/gateway.rs | 2 +- chirpstack/src/storage/multicast.rs | 8 ++++---- 14 files changed, 36 insertions(+), 45 deletions(-) diff --git a/chirpstack/src/api/internal.rs b/chirpstack/src/api/internal.rs index ce59f556..9fcb5f2a 100644 --- a/chirpstack/src/api/internal.rs +++ b/chirpstack/src/api/internal.rs @@ -289,8 +289,7 @@ impl InternalService for Internal { } else { Some( Uuid::from_str(&req_key.tenant_id) - .map_err(|e| e.status())? - .into(), + .map_err(|e| e.status())?, ) }; diff --git a/chirpstack/src/api/tenant.rs b/chirpstack/src/api/tenant.rs index 5d998bc4..483f0acd 100644 --- a/chirpstack/src/api/tenant.rs +++ b/chirpstack/src/api/tenant.rs @@ -258,8 +258,8 @@ impl TenantService for Tenant { .await?; let _ = tenant::add_user(tenant::TenantUser { + user_id, tenant_id: tenant_id.into(), - user_id: user_id.into(), is_admin: req_user.is_admin, is_device_admin: req_user.is_device_admin, is_gateway_admin: req_user.is_gateway_admin, diff --git a/chirpstack/src/api/user.rs b/chirpstack/src/api/user.rs index 81b2617a..8843ae20 100644 --- a/chirpstack/src/api/user.rs +++ b/chirpstack/src/api/user.rs @@ -65,7 +65,7 @@ impl UserService for User { tenant::add_user(tenant::TenantUser { tenant_id: tenant_id.into(), - user_id: u.id.into(), + user_id: u.id, is_admin: tu.is_admin, is_device_admin: tu.is_device_admin, is_gateway_admin: tu.is_gateway_admin, diff --git a/chirpstack/src/cmd/configfile.rs b/chirpstack/src/cmd/configfile.rs index b10ffe95..2db4921c 100644 --- a/chirpstack/src/cmd/configfile.rs +++ b/chirpstack/src/cmd/configfile.rs @@ -3,6 +3,7 @@ use handlebars::Handlebars; use super::super::config; pub fn run() { + #[allow(clippy::useless_vec)] let template = vec![ r#" # Logging configuration diff --git a/chirpstack/src/cmd/import_lorawan_device_profiles.rs b/chirpstack/src/cmd/import_lorawan_device_profiles.rs index b20f3d76..1590acb6 100644 --- a/chirpstack/src/cmd/import_lorawan_device_profiles.rs +++ b/chirpstack/src/cmd/import_lorawan_device_profiles.rs @@ -111,18 +111,16 @@ pub async fn run(dir: &Path) -> Result<()> { let vendors_dir = dir.join("vendors"); let vendors = fs::read_dir(vendors_dir)?; - for vendor in vendors { - if let Ok(vendor) = vendor { - if vendor.file_name() == "example-vendor" { - continue; - } + for vendor in vendors.flatten() { + if vendor.file_name() == "example-vendor" { + continue; + } - let span = span!(Level::INFO, "", vendor = ?vendor.file_name()); + let span = span!(Level::INFO, "", vendor = ?vendor.file_name()); - let vendor_dir = vendor.path(); - if vendor_dir.is_dir() { - handle_vendor(&vendor_dir).instrument(span).await?; - } + let vendor_dir = vendor.path(); + if vendor_dir.is_dir() { + handle_vendor(&vendor_dir).instrument(span).await?; } } diff --git a/chirpstack/src/downlink/data.rs b/chirpstack/src/downlink/data.rs index 67d381c3..df928112 100644 --- a/chirpstack/src/downlink/data.rs +++ b/chirpstack/src/downlink/data.rs @@ -466,10 +466,10 @@ impl Data { // * should not be pending // * should not be expired // * in case encrypted, should have a valid FCntDown - if qi.data.len() <= max_payload_size - && !qi.is_pending - && !(qi.expires_at.is_some() && qi.expires_at.unwrap() < Utc::now()) - && !(qi.is_encrypted + if !(qi.data.len() > max_payload_size + || qi.is_pending + || qi.expires_at.is_some() && qi.expires_at.unwrap() < Utc::now() + || qi.is_encrypted && (qi.f_cnt_down.unwrap_or_default() as u32) < ds.get_a_f_cnt_down()) { trace!(id = %qi.id, more_in_queue = more_in_queue, "Found device queue-item for downlink"); diff --git a/chirpstack/src/downlink/error.rs b/chirpstack/src/downlink/error.rs index 3a23348a..85e9106f 100644 --- a/chirpstack/src/downlink/error.rs +++ b/chirpstack/src/downlink/error.rs @@ -6,8 +6,8 @@ pub enum Error { Abort, #[error(transparent)] - AnyhowError(#[from] anyhow::Error), + Anyhow(#[from] anyhow::Error), #[error(transparent)] - StorageError(#[from] crate::storage::error::Error), + Storage(#[from] crate::storage::error::Error), } diff --git a/chirpstack/src/storage/device.rs b/chirpstack/src/storage/device.rs index 9f283301..5071dc93 100644 --- a/chirpstack/src/storage/device.rs +++ b/chirpstack/src/storage/device.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; use std::fmt; -use std::ops::{Deref, DerefMut}; use std::str::FromStr; use anyhow::{Context, Result}; @@ -146,15 +145,13 @@ impl Device { pub fn get_device_session(&self) -> Result<&internal::DeviceSession, Error> { self.device_session - .as_ref() - .map(|ds| ds.deref()) + .as_deref() .ok_or_else(|| Error::NotFound(self.dev_eui.to_string())) } pub fn get_device_session_mut(&mut self) -> Result<&mut internal::DeviceSession, Error> { self.device_session - .as_mut() - .map(|ds| ds.deref_mut()) + .as_deref_mut() .ok_or_else(|| Error::NotFound(self.dev_eui.to_string())) } diff --git a/chirpstack/src/storage/fields/big_decimal.rs b/chirpstack/src/storage/fields/big_decimal.rs index 987d5d85..3481e8b9 100644 --- a/chirpstack/src/storage/fields/big_decimal.rs +++ b/chirpstack/src/storage/fields/big_decimal.rs @@ -54,7 +54,7 @@ impl deserialize::FromSql for BigDecimal { #[cfg(feature = "postgres")] impl serialize::ToSql for BigDecimal { - fn to_sql<'b>(&self, out: &mut serialize::Output<'b, '_, Pg>) -> serialize::Result { + fn to_sql(&self, out: &mut serialize::Output<'_, '_, Pg>) -> serialize::Result { >::to_sql( &self.0, &mut out.reborrow(), diff --git a/chirpstack/src/storage/fields/dev_nonces.rs b/chirpstack/src/storage/fields/dev_nonces.rs index 43ed4d3e..5b97f511 100644 --- a/chirpstack/src/storage/fields/dev_nonces.rs +++ b/chirpstack/src/storage/fields/dev_nonces.rs @@ -17,15 +17,11 @@ type DevNoncesPgType = Array>; #[serde(transparent)] #[cfg_attr(feature = "postgres", diesel(sql_type = DevNoncesPgType))] #[cfg_attr(feature = "sqlite", diesel(sql_type = Text))] +#[derive(Default)] pub struct DevNonces(DevNoncesInner); pub type DevNoncesInner = Vec>; -impl std::default::Default for DevNonces { - fn default() -> Self { - Self(Vec::new()) - } -} impl std::convert::AsRef for DevNonces { fn as_ref(&self) -> &DevNoncesInner { @@ -62,7 +58,7 @@ impl deserialize::FromSql for DevNonces { #[cfg(feature = "postgres")] impl serialize::ToSql for DevNonces { - fn to_sql<'b>(&self, out: &mut serialize::Output<'b, '_, Pg>) -> serialize::Result { + fn to_sql(&self, out: &mut serialize::Output<'_, '_, Pg>) -> serialize::Result { >::to_sql( &self.0, &mut out.reborrow(), diff --git a/chirpstack/src/storage/fields/device_session.rs b/chirpstack/src/storage/fields/device_session.rs index 1d6c3123..27723287 100644 --- a/chirpstack/src/storage/fields/device_session.rs +++ b/chirpstack/src/storage/fields/device_session.rs @@ -34,9 +34,9 @@ impl std::convert::From<&internal::DeviceSession> for DeviceSession { } } -impl std::convert::Into for DeviceSession { - fn into(self) -> internal::DeviceSession { - self.0 +impl std::convert::From for internal::DeviceSession { + fn from(val: DeviceSession) -> Self { + val.0 } } diff --git a/chirpstack/src/storage/fields/uuid.rs b/chirpstack/src/storage/fields/uuid.rs index a2be1a78..539dfabf 100644 --- a/chirpstack/src/storage/fields/uuid.rs +++ b/chirpstack/src/storage/fields/uuid.rs @@ -21,13 +21,13 @@ impl std::convert::From for Uuid { impl std::convert::From<&uuid::Uuid> for Uuid { fn from(u: &uuid::Uuid) -> Self { - Self::from(u.clone()) + Self::from(*u) } } -impl std::convert::Into for Uuid { - fn into(self) -> uuid::Uuid { - self.0 +impl std::convert::From for uuid::Uuid { + fn from(val: Uuid) -> Self { + val.0 } } @@ -60,7 +60,7 @@ impl deserialize::FromSql for Uuid { #[cfg(feature = "postgres")] impl serialize::ToSql for Uuid { - fn to_sql<'b>(&self, out: &mut serialize::Output<'b, '_, Pg>) -> serialize::Result { + fn to_sql(&self, out: &mut serialize::Output<'_, '_, Pg>) -> serialize::Result { >::to_sql( &self.0, &mut out.reborrow(), diff --git a/chirpstack/src/storage/gateway.rs b/chirpstack/src/storage/gateway.rs index 1bbf8c07..b725d2cd 100644 --- a/chirpstack/src/storage/gateway.rs +++ b/chirpstack/src/storage/gateway.rs @@ -390,7 +390,7 @@ pub async fn get_counts_by_state(tenant_id: &Option) -> Result, _>(tenant_id.map(|u| fields::Uuid::from(u))).get_result(&mut get_async_db_conn().await?).await?; + "#).bind::, _>(tenant_id.map(fields::Uuid::from)).get_result(&mut get_async_db_conn().await?).await?; Ok(counts) } diff --git a/chirpstack/src/storage/multicast.rs b/chirpstack/src/storage/multicast.rs index a75f4a15..9e4c8125 100644 --- a/chirpstack/src/storage/multicast.rs +++ b/chirpstack/src/storage/multicast.rs @@ -465,7 +465,7 @@ pub async fn enqueue( for gateway_id in gateway_ids { let qi = MulticastGroupQueueItem { scheduler_run_after: scheduler_run_after_ts, - multicast_group_id: mg.id.into(), + multicast_group_id: mg.id, gateway_id: *gateway_id, f_cnt: mg.f_cnt, f_port: qi.f_port, @@ -473,7 +473,7 @@ pub async fn enqueue( emit_at_time_since_gps_epoch: Some( emit_at_time_since_gps_epoch.num_milliseconds(), ), - expires_at: qi.expires_at.clone(), + expires_at: qi.expires_at, ..Default::default() }; @@ -540,13 +540,13 @@ pub async fn enqueue( for gateway_id in gateway_ids { let qi = MulticastGroupQueueItem { scheduler_run_after: scheduler_run_after_ts, - multicast_group_id: mg.id.into(), + multicast_group_id: mg.id, gateway_id: *gateway_id, f_cnt: mg.f_cnt, f_port: qi.f_port, data: qi.data.clone(), emit_at_time_since_gps_epoch, - expires_at: qi.expires_at.clone(), + expires_at: qi.expires_at, ..Default::default() };