mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Fix all clippy warnings in the Rust backend
Addresses all 31 warnings emitted by cargo clippy: redundant field names in struct initialisers, unnecessary unwrap after is_some checks (replaced with if-let), needless borrows, filter+next replaced with find, iter().count() replaced with len(), clone on Copy type, and manual match-to-Option replaced with .ok(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
44d593fccc
commit
cb2b3c6af7
+16
-19
@@ -21,54 +21,51 @@ pub fn list_devices(
|
||||
// Prepare SQL and parameters
|
||||
let mut sql_statement = "SELECT mac_address, ipv4_address, vendor, last_seen, is_registered, owner, device_type FROM devices WHERE 1=1 ".to_string();
|
||||
let mut params: Vec<rusqlite::types::Value> = Vec::new();
|
||||
if is_registered.is_some() {
|
||||
debug!("Adding filter is_registered={}", is_registered.unwrap());
|
||||
if let Some(is_registered) = is_registered {
|
||||
debug!("Adding filter is_registered={}", is_registered);
|
||||
sql_statement.push_str("AND is_registered=? ");
|
||||
|
||||
params.push(is_registered.unwrap().into());
|
||||
params.push(is_registered.into());
|
||||
};
|
||||
if last_seen_from.is_some() {
|
||||
if let Some(last_seen_from) = last_seen_from {
|
||||
debug!(
|
||||
"Adding filter last_seen>={}",
|
||||
last_seen_from.unwrap().format("%Y-%m-%d %H:%M:%S")
|
||||
last_seen_from.format("%Y-%m-%d %H:%M:%S")
|
||||
);
|
||||
sql_statement.push_str("AND last_seen>=? ");
|
||||
params.push(
|
||||
last_seen_from
|
||||
.unwrap()
|
||||
.format("%Y-%m-%d %H:%M:%S")
|
||||
.to_string()
|
||||
.into(),
|
||||
);
|
||||
};
|
||||
if last_seen_to.is_some() {
|
||||
if let Some(last_seen_to) = last_seen_to {
|
||||
debug!(
|
||||
"Adding filter last_seen<={}",
|
||||
last_seen_to.unwrap().format("%Y-%m-%d %H:%M:%S")
|
||||
last_seen_to.format("%Y-%m-%d %H:%M:%S")
|
||||
);
|
||||
sql_statement.push_str("AND last_seen<=? ");
|
||||
params.push(
|
||||
last_seen_to
|
||||
.unwrap()
|
||||
.format("%Y-%m-%d %H:%M:%S")
|
||||
.to_string()
|
||||
.into(),
|
||||
);
|
||||
};
|
||||
if owner.is_some() {
|
||||
debug!("Adding filter owner={}", owner.clone().unwrap());
|
||||
if let Some(owner) = owner {
|
||||
debug!("Adding filter owner={}", owner);
|
||||
sql_statement.push_str("AND owner=? ");
|
||||
params.push(owner.unwrap().into());
|
||||
params.push(owner.into());
|
||||
};
|
||||
if device_type.is_some() {
|
||||
debug!("Adding filter device_type={}", device_type.clone().unwrap());
|
||||
if let Some(device_type) = device_type {
|
||||
debug!("Adding filter device_type={}", device_type);
|
||||
sql_statement.push_str("AND device_type=? ");
|
||||
params.push(device_type.unwrap().into());
|
||||
params.push(device_type.into());
|
||||
}
|
||||
if vendor.is_some() {
|
||||
debug!("Adding filter vendor={}", vendor.clone().unwrap());
|
||||
if let Some(vendor) = vendor {
|
||||
debug!("Adding filter vendor={}", vendor);
|
||||
sql_statement.push_str("AND vendor=? ");
|
||||
params.push(vendor.unwrap().into());
|
||||
params.push(vendor.into());
|
||||
}
|
||||
|
||||
let mut stmt = conn.prepare(sql_statement.as_str())?;
|
||||
|
||||
@@ -20,27 +20,26 @@ pub fn list(
|
||||
let mut params: Vec<rusqlite::types::Value> = Vec::new();
|
||||
|
||||
// Filters
|
||||
if is_new.is_some() {
|
||||
debug!("Adding filter is_new={}", is_new.unwrap());
|
||||
if let Some(is_new) = is_new {
|
||||
debug!("Adding filter is_new={}", is_new);
|
||||
sql_statement.push_str(" AND is_new=?");
|
||||
|
||||
params.push(is_new.unwrap().into());
|
||||
params.push(is_new.into());
|
||||
}
|
||||
|
||||
// List order
|
||||
sql_statement.push_str(" ORDER BY created_on DESC");
|
||||
|
||||
// Paging
|
||||
if page_offset.is_some() && page_limit.is_some() {
|
||||
if let (Some(page_offset), Some(page_limit)) = (page_offset, page_limit) {
|
||||
debug!(
|
||||
"Adding paging to list with offset={} and limit={}",
|
||||
page_offset.unwrap(),
|
||||
page_limit.unwrap()
|
||||
page_offset,
|
||||
page_limit
|
||||
);
|
||||
sql_statement.push_str(" LIMIT ? OFFSET ?");
|
||||
|
||||
params.push(page_limit.unwrap().into());
|
||||
params.push(page_offset.unwrap().into());
|
||||
params.push(page_limit.into());
|
||||
params.push(page_offset.into());
|
||||
};
|
||||
|
||||
let mut stmt = conn.prepare(sql_statement.as_str())?;
|
||||
|
||||
@@ -21,8 +21,7 @@ pub async fn find(interface: String) -> Result<Vec<Device>, Box<dyn std::error::
|
||||
let network_interface: NetworkInterface = match datalink::interfaces()
|
||||
.iter()
|
||||
.filter(|el| el.is_up())
|
||||
.filter(|el| el.name == interface)
|
||||
.next()
|
||||
.find(|el| el.name == interface)
|
||||
{
|
||||
Some(value) => value.clone(),
|
||||
None => {
|
||||
|
||||
@@ -51,7 +51,7 @@ pub async fn send_packet(
|
||||
ethernet_packet.set_payload(arp_packet.packet_mut());
|
||||
|
||||
tx.send_to(
|
||||
ðernet_packet.to_immutable().packet(),
|
||||
ethernet_packet.to_immutable().packet(),
|
||||
Some(interface.clone()),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ lazy_static! {
|
||||
let mut database = HashMap::new();
|
||||
let data = include_str!("../data/mac-vendors-export.json");
|
||||
|
||||
let json: Vec<MacRecord> = match serde_json::from_str(&data) {
|
||||
let json: Vec<MacRecord> = match serde_json::from_str(data) {
|
||||
Ok(value) => value,
|
||||
Err(error) => {
|
||||
error!(
|
||||
|
||||
@@ -25,10 +25,10 @@ impl Device {
|
||||
last_seen: DateTime<Utc>,
|
||||
) -> Self {
|
||||
Self {
|
||||
mac_address: mac_address,
|
||||
ipv4_address: ipv4_address,
|
||||
vendor: vendor,
|
||||
last_seen: last_seen,
|
||||
mac_address,
|
||||
ipv4_address,
|
||||
vendor,
|
||||
last_seen,
|
||||
is_registered: false,
|
||||
owner: "".to_string(),
|
||||
device_type: "".to_string(),
|
||||
|
||||
@@ -27,11 +27,11 @@ impl Notification {
|
||||
) -> Self {
|
||||
Self {
|
||||
id: -1,
|
||||
created_on: created_on,
|
||||
notification_type: notification_type,
|
||||
title: title,
|
||||
body: body,
|
||||
is_new: is_new,
|
||||
created_on,
|
||||
notification_type,
|
||||
title,
|
||||
body,
|
||||
is_new,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ pub async fn scan() -> Result<(), Box<dyn std::error::Error>> {
|
||||
device_finders::arp::find(get_settings().networking.interface.to_string()).await?;
|
||||
|
||||
info!("Done with ARP probes");
|
||||
info!("Found {} online devices", devices.iter().count());
|
||||
info!("Found {} online devices", devices.len());
|
||||
|
||||
// Process found devices
|
||||
for device in devices.iter() {
|
||||
|
||||
@@ -9,7 +9,7 @@ pub fn serialize<S: Serializer>(
|
||||
datetime: &DateTime<Utc>,
|
||||
serializer: S,
|
||||
) -> Result<S::Ok, S::Error> {
|
||||
time_to_json(datetime.clone()).serialize(serializer)
|
||||
time_to_json(*datetime).serialize(serializer)
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<DateTime<Utc>, D::Error> {
|
||||
|
||||
@@ -7,10 +7,7 @@ pub fn parse_parameter_bool(params: &HashMap<String, String>, name: &str) -> Opt
|
||||
if params.contains_key(name) {
|
||||
let param_value = params.get(name).unwrap().as_str();
|
||||
debug!("Found parameter {name} with value {}", param_value);
|
||||
match param_value.parse::<bool>() {
|
||||
Ok(value) => Some(value),
|
||||
Err(_) => None,
|
||||
}
|
||||
param_value.parse::<bool>().ok()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -20,10 +17,7 @@ pub fn parse_parameter_int(params: &HashMap<String, String>, name: &str) -> Opti
|
||||
if params.contains_key(name) {
|
||||
let param_value = params.get(name).unwrap().as_str();
|
||||
debug!("Found parameter {name} with value {}", param_value);
|
||||
match param_value.parse::<i64>() {
|
||||
Ok(value) => Some(value),
|
||||
Err(_) => None,
|
||||
}
|
||||
param_value.parse::<i64>().ok()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user