Fix clippy feedback.

This commit is contained in:
Orne Brocaar 2023-04-13 22:06:44 +01:00
parent f71d30ca83
commit 0a294e41b5
15 changed files with 36 additions and 63 deletions

View File

@ -37,11 +37,10 @@ impl Algorithm {
} }
nb_step -= 1; nb_step -= 1;
} else { } else {
if tx_power_index > 0 {
// Increase the tx-power. // Increase the tx-power.
// (note that a decrease in index increases the tx-power) // (note that a decrease in index increases the tx-power)
tx_power_index -= 1; // Subtract only if > 0
} tx_power_index = tx_power_index.saturating_sub(1);
nb_step += 1; nb_step += 1;
} }

View File

@ -844,7 +844,7 @@ impl InternalService for Internal {
out.rx1_delay = region_conf.network.rx1_delay as u32; out.rx1_delay = region_conf.network.rx1_delay as u32;
out.rx1_dr_offset = region_conf.network.rx1_dr_offset as u32; out.rx1_dr_offset = region_conf.network.rx1_dr_offset as u32;
out.rx2_dr = region_conf.network.rx2_dr as u32; out.rx2_dr = region_conf.network.rx2_dr as u32;
out.rx2_frequency = region_conf.network.rx2_frequency as u32; out.rx2_frequency = region_conf.network.rx2_frequency;
out.class_b_ping_slot_dr = region_conf.network.class_b.ping_slot_dr as u32; out.class_b_ping_slot_dr = region_conf.network.class_b.ping_slot_dr as u32;
out.class_b_ping_slot_frequency = region_conf.network.class_b.ping_slot_frequency; out.class_b_ping_slot_frequency = region_conf.network.class_b.ping_slot_frequency;
} }

View File

@ -223,7 +223,7 @@ pub fn ul_meta_data_to_rx_info(ul_meta_data: &ULMetaData) -> Result<Vec<gw::Upli
gateway_id: hex::encode(&gw_info.id), gateway_id: hex::encode(&gw_info.id),
context: gw_info.ul_token.clone(), context: gw_info.ul_token.clone(),
rssi: gw_info.rssi.unwrap_or_default() as i32, rssi: gw_info.rssi.unwrap_or_default() as i32,
snr: gw_info.snr.unwrap_or_default() as f32, snr: gw_info.snr.unwrap_or_default(),
location: if gw_info.lat.is_some() && gw_info.lon.is_some() { location: if gw_info.lat.is_some() && gw_info.lon.is_some() {
Some(common::Location { Some(common::Location {
latitude: gw_info.lat.unwrap(), latitude: gw_info.lat.unwrap(),

View File

@ -287,7 +287,7 @@ impl CayenneLpp {
val.fields.insert( val.fields.insert(
format!("{}", k), format!("{}", k),
pbjson_types::Value { pbjson_types::Value {
kind: Some(pbjson_types::value::Kind::NumberValue(*v as f64)), kind: Some(pbjson_types::value::Kind::NumberValue(*v)),
}, },
); );
} }
@ -305,7 +305,7 @@ impl CayenneLpp {
val.fields.insert( val.fields.insert(
format!("{}", k), format!("{}", k),
pbjson_types::Value { pbjson_types::Value {
kind: Some(pbjson_types::value::Kind::NumberValue(*v as f64)), kind: Some(pbjson_types::value::Kind::NumberValue(*v)),
}, },
); );
} }
@ -359,7 +359,7 @@ impl CayenneLpp {
val.fields.insert( val.fields.insert(
format!("{}", k), format!("{}", k),
pbjson_types::Value { pbjson_types::Value {
kind: Some(pbjson_types::value::Kind::NumberValue(*v as f64)), kind: Some(pbjson_types::value::Kind::NumberValue(*v)),
}, },
); );
} }
@ -377,7 +377,7 @@ impl CayenneLpp {
val.fields.insert( val.fields.insert(
format!("{}", k), format!("{}", k),
pbjson_types::Value { pbjson_types::Value {
kind: Some(pbjson_types::value::Kind::NumberValue(*v as f64)), kind: Some(pbjson_types::value::Kind::NumberValue(*v)),
}, },
); );
} }

View File

@ -44,7 +44,7 @@ impl serialize::ToSql<Text, Pg> for Codec
where where
str: serialize::ToSql<Text, Pg>, str: serialize::ToSql<Text, Pg>,
{ {
fn to_sql<'b>(&self, out: &mut serialize::Output<'b, '_, Pg>) -> serialize::Result { fn to_sql(&self, out: &mut serialize::Output<'_, '_, Pg>) -> serialize::Result {
<str as serialize::ToSql<Text, Pg>>::to_sql(&self.to_string(), &mut out.reborrow()) <str as serialize::ToSql<Text, Pg>>::to_sql(&self.to_string(), &mut out.reborrow())
} }
} }

View File

@ -13,7 +13,7 @@ lazy_static! {
static ref CONFIG: Mutex<Arc<Configuration>> = Mutex::new(Arc::new(Default::default())); static ref CONFIG: Mutex<Arc<Configuration>> = Mutex::new(Arc::new(Default::default()));
} }
#[derive(Serialize, Deserialize, Clone)] #[derive(Default, Serialize, Deserialize, Clone)]
#[serde(default)] #[serde(default)]
pub struct Configuration { pub struct Configuration {
pub logging: Logging, pub logging: Logging,
@ -33,27 +33,6 @@ pub struct Configuration {
pub regions: Vec<Region>, pub regions: Vec<Region>,
} }
impl Default for Configuration {
fn default() -> Self {
Configuration {
logging: Default::default(),
postgresql: Default::default(),
redis: Default::default(),
api: Default::default(),
gateway: Default::default(),
network: Default::default(),
monitoring: Default::default(),
integration: Default::default(),
codec: Default::default(),
user_authentication: Default::default(),
join_server: Default::default(),
backend_interfaces: Default::default(),
roaming: Default::default(),
keks: Vec::new(),
regions: vec![],
}
}
}
#[derive(Serialize, Deserialize, Clone)] #[derive(Serialize, Deserialize, Clone)]
#[serde(default)] #[serde(default)]

View File

@ -23,10 +23,7 @@ pub fn select_downlink_gateway(
min_snr_margin: f32, min_snr_margin: f32,
rx_info: &mut internal::DeviceGatewayRxInfo, rx_info: &mut internal::DeviceGatewayRxInfo,
) -> Result<internal::DeviceGatewayRxInfoItem> { ) -> Result<internal::DeviceGatewayRxInfoItem> {
rx_info.items = rx_info rx_info.items.retain(|rx_info| {
.items
.iter()
.filter(|rx_info| {
if let Some(tenant_id) = &tenant_id { if let Some(tenant_id) = &tenant_id {
if tenant_id.as_bytes().to_vec() == rx_info.tenant_id { if tenant_id.as_bytes().to_vec() == rx_info.tenant_id {
// The tenant is the same as the gateway tenant. // The tenant is the same as the gateway tenant.
@ -41,9 +38,7 @@ pub fn select_downlink_gateway(
// is_private_down=true. // is_private_down=true.
!rx_info.is_private_down !rx_info.is_private_down
} }
}) });
.cloned()
.collect();
if rx_info.items.is_empty() { if rx_info.items.is_empty() {
return Err(anyhow!( return Err(anyhow!(

View File

@ -113,7 +113,7 @@ impl JoinAccept<'_> {
.gateway_tenant_id_map .gateway_tenant_id_map
.get(&gw_id) .get(&gw_id)
.map(|v| v.into_bytes().to_vec()) .map(|v| v.into_bytes().to_vec())
.unwrap_or_else(|| Vec::new()), .unwrap_or_else(Vec::new),
} }
}) })
.collect(), .collect(),

View File

@ -92,7 +92,7 @@ impl PassiveRoamingDownlink {
.gateway_tenant_id_map .gateway_tenant_id_map
.get(&gw_id) .get(&gw_id)
.map(|v| v.into_bytes().to_vec()) .map(|v| v.into_bytes().to_vec())
.unwrap_or_else(|| Vec::new()), .unwrap_or_else(Vec::new),
} }
}) })
.collect(), .collect(),
@ -127,7 +127,7 @@ impl PassiveRoamingDownlink {
let dl_freq_1 = self.dl_meta_data.dl_freq_1.unwrap(); let dl_freq_1 = self.dl_meta_data.dl_freq_1.unwrap();
let dl_freq_1 = (dl_freq_1 * 1_000_000.0) as u32; let dl_freq_1 = (dl_freq_1 * 1_000_000.0) as u32;
let data_rate_1 = self.dl_meta_data.data_rate_1.unwrap(); let data_rate_1 = self.dl_meta_data.data_rate_1.unwrap();
let data_rate_1 = self.region_conf.get_data_rate(data_rate_1 as u8)?; let data_rate_1 = self.region_conf.get_data_rate(data_rate_1)?;
let rx_delay_1 = self.dl_meta_data.rx_delay_1.unwrap(); let rx_delay_1 = self.dl_meta_data.rx_delay_1.unwrap();
let mut tx_info = gw::DownlinkTxInfo { let mut tx_info = gw::DownlinkTxInfo {
@ -169,7 +169,7 @@ impl PassiveRoamingDownlink {
let dl_freq_2 = self.dl_meta_data.dl_freq_2.unwrap(); let dl_freq_2 = self.dl_meta_data.dl_freq_2.unwrap();
let dl_freq_2 = (dl_freq_2 * 1_000_000.0) as u32; let dl_freq_2 = (dl_freq_2 * 1_000_000.0) as u32;
let data_rate_2 = self.dl_meta_data.data_rate_2.unwrap(); let data_rate_2 = self.dl_meta_data.data_rate_2.unwrap();
let data_rate_2 = self.region_conf.get_data_rate(data_rate_2 as u8)?; let data_rate_2 = self.region_conf.get_data_rate(data_rate_2)?;
let rx_delay_1 = self.dl_meta_data.rx_delay_1.unwrap(); let rx_delay_1 = self.dl_meta_data.rx_delay_1.unwrap();
let mut tx_info = gw::DownlinkTxInfo { let mut tx_info = gw::DownlinkTxInfo {

View File

@ -554,7 +554,7 @@ impl<'de> Visitor<'de> for Eui64WrapperVisitor {
E: de::Error, E: de::Error,
{ {
let s = value.to_string().replace('-', ""); let s = value.to_string().replace('-', "");
let b = hex::decode(&s).map_err(|e| E::custom(format!("{}", e)))?; let b = hex::decode(s).map_err(|e| E::custom(format!("{}", e)))?;
let eui64 = EUI64::from_slice(&b).map_err(|e| E::custom(format!("{}", e)))?; let eui64 = EUI64::from_slice(&b).map_err(|e| E::custom(format!("{}", e)))?;
Ok(Eui64Wrapper(eui64)) Ok(Eui64Wrapper(eui64))
} }

View File

@ -129,7 +129,7 @@ impl serialize::ToSql<Text, Pg> for IntegrationKind
where where
str: serialize::ToSql<Text, Pg>, str: serialize::ToSql<Text, Pg>,
{ {
fn to_sql<'b>(&self, out: &mut serialize::Output<'b, '_, Pg>) -> serialize::Result { fn to_sql(&self, out: &mut serialize::Output<'_, '_, Pg>) -> serialize::Result {
<str as serialize::ToSql<Text, Pg>>::to_sql(&self.to_string(), &mut out.reborrow()) <str as serialize::ToSql<Text, Pg>>::to_sql(&self.to_string(), &mut out.reborrow())
} }
} }
@ -158,7 +158,7 @@ impl deserialize::FromSql<Jsonb, Pg> for IntegrationConfiguration {
} }
impl serialize::ToSql<Jsonb, Pg> for IntegrationConfiguration { impl serialize::ToSql<Jsonb, Pg> for IntegrationConfiguration {
fn to_sql<'b>(&self, out: &mut serialize::Output<'b, '_, Pg>) -> serialize::Result { fn to_sql(&self, out: &mut serialize::Output<'_, '_, Pg>) -> serialize::Result {
let value = serde_json::to_value(self)?; let value = serde_json::to_value(self)?;
<serde_json::Value as serialize::ToSql<Jsonb, Pg>>::to_sql(&value, &mut out.reborrow()) <serde_json::Value as serialize::ToSql<Jsonb, Pg>>::to_sql(&value, &mut out.reborrow())
} }

View File

@ -91,7 +91,7 @@ impl deserialize::FromSql<Jsonb, Pg> for Measurements {
} }
impl serialize::ToSql<Jsonb, Pg> for Measurements { impl serialize::ToSql<Jsonb, Pg> for Measurements {
fn to_sql<'b>(&self, out: &mut serialize::Output<'b, '_, Pg>) -> serialize::Result { fn to_sql(&self, out: &mut serialize::Output<'_, '_, Pg>) -> serialize::Result {
let value = serde_json::to_value(&self.0)?; let value = serde_json::to_value(&self.0)?;
<serde_json::Value as serialize::ToSql<Jsonb, Pg>>::to_sql(&value, &mut out.reborrow()) <serde_json::Value as serialize::ToSql<Jsonb, Pg>>::to_sql(&value, &mut out.reborrow())
} }

View File

@ -50,7 +50,7 @@ pub async fn global_search(
let search = search.to_string(); let search = search.to_string();
let (query, tags) = parse_search_query(&search); let (query, tags) = parse_search_query(&search);
let query = format!("%{}%", query); let query = format!("%{}%", query);
let tags = serde_json::to_value(&tags).context("To serde_json value")?; let tags = serde_json::to_value(tags).context("To serde_json value")?;
move || -> Result<Vec<SearchResult>, Error> { move || -> Result<Vec<SearchResult>, Error> {
let mut c = get_db_conn()?; let mut c = get_db_conn()?;

View File

@ -288,7 +288,7 @@ impl Data {
.gateway_tenant_id_map .gateway_tenant_id_map
.get(&gw_id) .get(&gw_id)
.map(|v| v.into_bytes().to_vec()) .map(|v| v.into_bytes().to_vec())
.unwrap_or_else(|| Vec::new()), .unwrap_or_else(Vec::new),
} }
}) })
.collect(), .collect(),

View File

@ -375,13 +375,13 @@ fn filter_rx_info_by_tenant_id(tenant_id: Uuid, uplink: &mut UplinkFrameSet) ->
.gateway_private_up_map .gateway_private_up_map
.get(&gateway_id) .get(&gateway_id)
.cloned() .cloned()
.unwrap_or_else(|| true) .unwrap_or(true)
|| force_gws_private) || force_gws_private)
|| uplink || uplink
.gateway_tenant_id_map .gateway_tenant_id_map
.get(&gateway_id) .get(&gateway_id)
.cloned() .cloned()
.unwrap_or_else(|| Uuid::new_v4()) .unwrap_or_else(Uuid::new_v4)
== tenant_id == tenant_id
{ {
rx_info_set.push(rx_info.clone()); rx_info_set.push(rx_info.clone());