diff --git a/src/main.rs b/src/main.rs index fa14876c6ea98322c8b35b9f049ecf2db9768e50..2a17c845d340434942d47ca5723a76ee84ac48b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilte use ui::ComposableView; static MSG_MANAGER: OnceLock<Mutex<MessageManager>> = OnceLock::new(); -static MAVLINK_PROFILE: LazyLock<ReflectionContext> = LazyLock::new(|| ReflectionContext::new()); +static MAVLINK_PROFILE: LazyLock<ReflectionContext> = LazyLock::new(ReflectionContext::new); fn main() -> Result<(), eframe::Error> { // set up logging (USE RUST_LOG=debug to see logs) diff --git a/src/mavlink.rs b/src/mavlink.rs index 5b2214f49eab10352ebbb16bba65a0a03c1c6560..b0ce8e5e326e13b35d99981cab3b614be3bc6206 100644 --- a/src/mavlink.rs +++ b/src/mavlink.rs @@ -52,7 +52,9 @@ impl MessageManager { pub fn stop_listening(&mut self) { self.running_flag.store(false, Ordering::Relaxed); - self.task.take().map(|t| t.abort()); + if let Some(t) = self.task.take() { + t.abort() + } } pub fn listen_from_ethernet_port(&mut self, port: u16) { @@ -168,7 +170,7 @@ impl ReflectionContext { .unwrap_or_else(|| { panic!("Message ID {} not found in profile", message_id); }) - .into_iter() + .iter() .map(|f| f.name.as_str()) .collect() } @@ -182,19 +184,21 @@ impl ReflectionContext { .unwrap_or_else(|| { panic!("Message ID {} not found in profile", message_id); }) - .into_iter() - .filter(|f| match f.mavtype { - MavType::UInt8 - | MavType::UInt16 - | MavType::UInt32 - | MavType::UInt64 - | MavType::Int8 - | MavType::Int16 - | MavType::Int32 - | MavType::Int64 - | MavType::Float - | MavType::Double => true, - _ => false, + .iter() + .filter(|f| { + matches!( + f.mavtype, + MavType::UInt8 + | MavType::UInt16 + | MavType::UInt32 + | MavType::UInt64 + | MavType::Int8 + | MavType::Int16 + | MavType::Int32 + | MavType::Int64 + | MavType::Float + | MavType::Double + ) }) .map(|f| f.name.as_str()) .collect() @@ -209,7 +213,7 @@ impl ReflectionContext { .unwrap_or_else(|| { panic!("Message {} not found in profile", message_name); }) - .into_iter() + .iter() .map(|f| f.name.as_str()) .collect() } diff --git a/src/ui/panes.rs b/src/ui/panes.rs index 9aebb54415524b2339a11c5abafdb58cc802b5b4..e963f0fbd5f785d0d5af9170b1e049d7bd05f45a 100644 --- a/src/ui/panes.rs +++ b/src/ui/panes.rs @@ -7,19 +7,11 @@ use serde::{Deserialize, Serialize}; use super::composable_view::PaneResponse; -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, Serialize, Deserialize)] pub struct Pane { pub pane: PaneKind, } -impl Default for Pane { - fn default() -> Self { - Self { - pane: PaneKind::default(), - } - } -} - impl Pane { pub fn boxed(pane: PaneKind) -> Box<Self> { Box::new(Self { pane }) diff --git a/src/ui/panes/default.rs b/src/ui/panes/default.rs index 25851db11250d595570ed10586a2c9add093914d..06cba95093d57307c9476867c777731ac9459dbb 100644 --- a/src/ui/panes/default.rs +++ b/src/ui/panes/default.rs @@ -7,22 +7,13 @@ use crate::ui::{ utils::{vertically_centered, SizingMemo}, }; -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, Serialize, Deserialize)] pub struct DefaultPane { #[serde(skip)] centering_memo: SizingMemo, contains_pointer: bool, } -impl Default for DefaultPane { - fn default() -> Self { - DefaultPane { - centering_memo: SizingMemo::default(), - contains_pointer: false, - } - } -} - impl PaneBehavior for DefaultPane { fn ui(&mut self, ui: &mut egui::Ui) -> PaneResponse { let mut response = PaneResponse::default(); diff --git a/src/ui/panes/plot_2d.rs b/src/ui/panes/plot_2d.rs index ecaec8c3083a15529e1e31abdb7c9164e15cd1cd..1a3282e70c09aeab3ec48a33e804394eda977e1d 100644 --- a/src/ui/panes/plot_2d.rs +++ b/src/ui/panes/plot_2d.rs @@ -78,7 +78,7 @@ impl PaneBehavior for Plot2DPane { .lock() .get_message(self.msg_id) .map(|msg| { - msg.into_iter() + msg.iter() .map(|msg| { let value: serde_json::Value = serde_json::to_value(msg.message.clone()).unwrap(); @@ -100,7 +100,7 @@ impl PaneBehavior for Plot2DPane { for i in 0..self.fields_y.len() { let plot_line: Vec<[f64; 2]> = acc_points .iter() - .map(|(timestamp, acc)| [*timestamp as f64, acc[i] as f64]) + .map(|(timestamp, acc)| [{ *timestamp }, acc[i]]) .collect(); plot_lines.push(plot_line); } @@ -190,13 +190,12 @@ impl Plot2DPane { let mut field_x = fields .contains(&self.field_x.as_str()) .then(|| self.field_x.clone()) - .or(fields.get(0).map(|s| s.to_string())); + .or(fields.first().map(|s| s.to_string())); // get the second field that is in the list of fields or the previous if valid let mut field_y = self .fields_y - .get(0) - .map(|s| fields.contains(&s.as_str()).then_some(s.to_owned())) - .flatten() + .first() + .and_then(|s| fields.contains(&s.as_str()).then_some(s.to_owned())) .or(fields.get(1).map(|s| s.to_string())); // if fields are valid, show the combo boxes for the x_axis @@ -244,20 +243,19 @@ impl Plot2DPane { // if we have fields left, show the add button let fields_left_to_draw = fields.len().saturating_sub(fields_selected); - if fields_left_to_draw > 0 { - if ui + if fields_left_to_draw > 0 + && ui .button("Add Y Axis") .on_hover_text("Add another Y axis") .clicked() - { - self.fields_y.push(fields[fields_selected].to_string()); - } + { + self.fields_y.push(fields[fields_selected].to_string()); } // update fields and flag for active plot self.field_x = field_x.unwrap_or_default(); if field_y.is_some() { - if self.fields_y.get(0).is_none() { + if self.fields_y.first().is_none() { self.fields_y.push(field_y.unwrap()); } else { self.fields_y[0] = field_y.unwrap();