From 54d582504f3510844e5d889f659b4fabc34ced96 Mon Sep 17 00:00:00 2001 From: Orne Brocaar Date: Mon, 1 Aug 2022 10:24:15 +0100 Subject: [PATCH] Fix clippy warnings. --- lrwn/src/lib.rs | 2 +- lrwn/src/netid.rs | 8 +------- lrwn/src/region/mod.rs | 25 ++++++++++++++----------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/lrwn/src/lib.rs b/lrwn/src/lib.rs index 522ad713..cd330a54 100644 --- a/lrwn/src/lib.rs +++ b/lrwn/src/lib.rs @@ -72,5 +72,5 @@ pub fn get_tx_param_setup_eirp(i: u8) -> Result { EIRP_INDEX .get(i as usize) .cloned() - .ok_or(anyhow!("Index does not exist")) + .ok_or_else(|| anyhow!("Index does not exist")) } diff --git a/lrwn/src/netid.rs b/lrwn/src/netid.rs index 88f57e13..b431af85 100644 --- a/lrwn/src/netid.rs +++ b/lrwn/src/netid.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use crate::Error; -#[derive(PartialEq, Clone, Copy, Hash, Eq)] +#[derive(Default, PartialEq, Clone, Copy, Hash, Eq)] pub struct NetID([u8; 3]); impl NetID { @@ -76,12 +76,6 @@ impl NetID { } } -impl Default for NetID { - fn default() -> Self { - NetID([0, 0, 0]) - } -} - impl fmt::Display for NetID { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", hex::encode(self.0)) diff --git a/lrwn/src/region/mod.rs b/lrwn/src/region/mod.rs index f658ecf2..bdb65526 100644 --- a/lrwn/src/region/mod.rs +++ b/lrwn/src/region/mod.rs @@ -472,7 +472,7 @@ impl RegionBaseConfig { Ok(self .data_rates .get(&dr) - .ok_or(anyhow!("Unknown data-rate index"))? + .ok_or_else(|| anyhow!("Unknown data-rate index"))? .modulation .clone()) } @@ -488,35 +488,38 @@ impl RegionBaseConfig { None => self .max_payload_size_per_dr .get(&MacVersion::Latest) - .ok_or(anyhow!("Unknown mac-version"))?, + .ok_or_else(|| anyhow!("Unknown mac-version"))?, }; let dr_map = match reg_params_map.get(®_params_revision) { Some(v) => v, None => reg_params_map .get(&Revision::Latest) - .ok_or(anyhow!("Unknown revision"))?, + .ok_or_else(|| anyhow!("Unknown revision"))?, }; - Ok(dr_map.get(&dr).ok_or(anyhow!("Invalid data-rate"))?.clone()) + Ok(dr_map + .get(&dr) + .ok_or_else(|| anyhow!("Invalid data-rate"))? + .clone()) } fn get_rx1_data_rate_index(&self, uplink_dr: u8, rx1_dr_offset: usize) -> Result { let offset_vec = self .rx1_data_rate_table .get(&uplink_dr) - .ok_or(anyhow!("Unknown data-rate"))?; + .ok_or_else(|| anyhow!("Unknown data-rate"))?; Ok(*offset_vec .get(rx1_dr_offset) - .ok_or(anyhow!("Invalid rx1 data-rate offset"))?) + .ok_or_else(|| anyhow!("Invalid rx1 data-rate offset"))?) } fn get_tx_power_offset(&self, tx_power: usize) -> Result { Ok(*self .tx_power_offsets .get(tx_power) - .ok_or(anyhow!("Invalid tx-power"))?) + .ok_or_else(|| anyhow!("Invalid tx-power"))?) } fn add_channel(&mut self, frequency: u32, min_dr: u8, max_dr: u8) -> Result<()> { @@ -544,7 +547,7 @@ impl RegionBaseConfig { Ok(self .uplink_channels .get(channel) - .ok_or(anyhow!("Invalid channel"))? + .ok_or_else(|| anyhow!("Invalid channel"))? .clone()) } @@ -589,7 +592,7 @@ impl RegionBaseConfig { Ok(self .downlink_channels .get(channel) - .ok_or(anyhow!("Invalid channel"))? + .ok_or_else(|| anyhow!("Invalid channel"))? .clone()) } @@ -597,7 +600,7 @@ impl RegionBaseConfig { let mut channel = self .uplink_channels .get_mut(channel) - .ok_or(anyhow!("Invalid channel"))?; + .ok_or_else(|| anyhow!("Invalid channel"))?; channel.enabled = false; Ok(()) } @@ -606,7 +609,7 @@ impl RegionBaseConfig { let mut channel = self .uplink_channels .get_mut(channel) - .ok_or(anyhow!("Invalid channel"))?; + .ok_or_else(|| anyhow!("Invalid channel"))?; channel.enabled = true; Ok(()) }