From 25ded6d0bf41c753706339bf7ca0df32d49e3f5a Mon Sep 17 00:00:00 2001 From: Andrew Straw Date: Mon, 18 Nov 2024 09:25:00 +0100 Subject: [PATCH] clippy fixes --- bg-movie-writer/src/lib.rs | 19 +++---- .../src/bin/compute-flydra1-compat.rs | 4 +- braid-process-video/src/output_braidz.rs | 6 +- braid/braid-run/src/main.rs | 2 +- braid/braid-run/src/mainbrain.rs | 4 +- braidz-parser/braidz-chunked-iter/src/lib.rs | 2 +- braidz-parser/src/incremental_parser.rs | 2 +- ci2-pyloncxx/src/feature_cache.rs | 8 +-- ci2-pyloncxx/src/lib.rs | 57 ++++++++----------- ci2-remote-control/src/lib.rs | 2 +- flydra-feature-detector/src/lib.rs | 2 +- flydra-types/src/lib.rs | 6 +- flydra-types/src/timestamp.rs | 2 +- flydra-types/src/timestamp_opt_f64.rs | 2 +- flydra2/src/connected_camera_manager.rs | 10 +--- flydra2/src/flydra2.rs | 22 +++---- flydra2/src/mini_arenas.rs | 10 ++-- flydra2/src/model_server.rs | 7 +-- flytrax-csv-to-braidz/src/lib.rs | 8 +-- freemovr-calibration/src/lib.rs | 6 +- media-utils/ffmpeg-writer/src/lib.rs | 9 ++- media-utils/y4m-writer/src/lib.rs | 20 +++---- strand-cam/src/cli_app.rs | 2 +- strand-cam/src/datagram_socket.rs | 2 +- strand-cam/src/frame_process_task.rs | 2 +- strand-cam/src/strand-cam.rs | 25 +++----- .../src/components/video_field.rs | 3 +- strand-cam/yew_frontend/src/lib.rs | 12 +--- tracking/src/observation_model_2d.rs | 2 +- 29 files changed, 109 insertions(+), 149 deletions(-) diff --git a/bg-movie-writer/src/lib.rs b/bg-movie-writer/src/lib.rs index 1f221e660..2498d69bf 100644 --- a/bg-movie-writer/src/lib.rs +++ b/bg-movie-writer/src/lib.rs @@ -135,7 +135,7 @@ where { None, Mp4Writer(Mp4Writer<'lib, T>), - FfmpegWriter(MyFfmpegWriter), + FfmpegWriter(Box), } impl<'lib, T> RawWriter<'lib, T> @@ -143,10 +143,7 @@ where T: Write + Seek, { fn is_none(&self) -> bool { - match self { - Self::None => true, - _ => false, - } + matches!(self, Self::None) } } @@ -197,8 +194,8 @@ impl MyFfmpegWriter { count: 0, }) } - fn write<'a, IM, FMT>( - &'a mut self, + fn write( + &mut self, frame: &IM, timestamp: chrono::DateTime, ) -> Result<()> @@ -220,7 +217,7 @@ impl MyFfmpegWriter { } } -fn launch_runner<'lib>( +fn launch_runner( format_str_mp4: String, recording_config: ci2_remote_control::RecordingConfig, size: usize, @@ -307,10 +304,10 @@ fn launch_runner<'lib>( )); } Ffmpeg(c) => { - raw = RawWriter::FfmpegWriter(thread_try!( + raw = RawWriter::FfmpegWriter(Box::new(thread_try!( err_tx, - MyFfmpegWriter::new(&mp4_filename, &c) - )); + MyFfmpegWriter::new(&mp4_filename, c) + ))); } }; } diff --git a/braid-offline/src/bin/compute-flydra1-compat.rs b/braid-offline/src/bin/compute-flydra1-compat.rs index 106f1e583..85d413e58 100644 --- a/braid-offline/src/bin/compute-flydra1-compat.rs +++ b/braid-offline/src/bin/compute-flydra1-compat.rs @@ -37,7 +37,7 @@ pub struct FilteredObservations { } fn no_data_row(obj_id: u32, frame: SyncFno) -> KalmanEstimatesRow { - let nan: f64 = std::f64::NAN; + let nan: f64 = f64::NAN; KalmanEstimatesRow { obj_id, @@ -158,7 +158,7 @@ fn save_data_association_ascending( let mut kalman_estimates_iter = kalman_estimates_reader.into_deserialize::(); let kest_frame_iter = AscendingGroupIter::new(&mut kalman_estimates_iter).early_eof_ok(); - let nan: f32 = std::f32::NAN; + let nan: f32 = f32::NAN; let opt_next_da_row = da_row_frame_iter.next(); if opt_next_da_row.is_none() { diff --git a/braid-process-video/src/output_braidz.rs b/braid-process-video/src/output_braidz.rs index 819a0b961..b305ededa 100644 --- a/braid-process-video/src/output_braidz.rs +++ b/braid-process-video/src/output_braidz.rs @@ -188,11 +188,11 @@ impl BraidStorage { let pt = flydra_types::FlydraRawUdpPoint { x0_abs: *xy.0, y0_abs: *xy.1, - area: std::f64::NAN, + area: f64::NAN, maybe_slope_eccentricty: None, cur_val: 0, - mean_val: std::f64::NAN, - sumsqf_val: std::f64::NAN, + mean_val: f64::NAN, + sumsqf_val: f64::NAN, }; flydra2::NumberedRawUdpPoint { idx: idx.try_into().unwrap(), diff --git a/braid/braid-run/src/main.rs b/braid/braid-run/src/main.rs index 97da761fe..661c47689 100644 --- a/braid/braid-run/src/main.rs +++ b/braid/braid-run/src/main.rs @@ -71,7 +71,7 @@ fn launch_strand_cam( let cam_name = camera.name.clone(); let mut exec = std::process::Command::new(&exe); - let args = compute_strand_cam_args(&camera, mainbrain_internal_addr)?; + let args = compute_strand_cam_args(camera, mainbrain_internal_addr)?; exec.args(&args); debug!("exec: {:?}", exec); let mut obj = exec.spawn().context(format!( diff --git a/braid/braid-run/src/mainbrain.rs b/braid/braid-run/src/mainbrain.rs index 2bbb4eacf..1c859291b 100644 --- a/braid/braid-run/src/mainbrain.rs +++ b/braid/braid-run/src/mainbrain.rs @@ -379,7 +379,7 @@ async fn launch_braid_http_backend( let urls = mainbrain_server_info.build_urls()?; for url in urls.iter() { info!("Predicted URL: {url}"); - if !flydra_types::is_loopback(&url) { + if !flydra_types::is_loopback(url) { println!("QR code for {url}"); display_qr_url(&format!("{url}")); } @@ -1153,7 +1153,7 @@ pub(crate) async fn do_run_forever( packet.block_id, ); - assert!(packet.points.len() < u8::max_value() as usize); + assert!(packet.points.len() < u8::MAX as usize); let points = packet .points .into_iter() diff --git a/braidz-parser/braidz-chunked-iter/src/lib.rs b/braidz-parser/braidz-chunked-iter/src/lib.rs index 4e0f8544b..0bbdcc444 100644 --- a/braidz-parser/braidz-chunked-iter/src/lib.rs +++ b/braidz-parser/braidz-chunked-iter/src/lib.rs @@ -49,7 +49,7 @@ where )); } ChunkStartAndDuration::Frame(start_frame, n_frames_in_chunk) => { - let next_u64: u64 = next.try_into().unwrap(); + let next_u64: u64 = next.into(); let n_frames_in_chunk_u64: u64 = (*n_frames_in_chunk).try_into().unwrap(); let stop_dur = n_frames_in_chunk_u64 * next_u64; stop_frame = Some(*start_frame + stop_dur); diff --git a/braidz-parser/src/incremental_parser.rs b/braidz-parser/src/incremental_parser.rs index ee2e02679..771cbe281 100644 --- a/braidz-parser/src/incremental_parser.rs +++ b/braidz-parser/src/incremental_parser.rs @@ -133,7 +133,7 @@ impl IncrementalParser { .unwrap(); // Parse fps and tracking parameters from textlog. - let mut expected_fps = std::f64::NAN; + let mut expected_fps = f64::NAN; let tracking_params: Option = { let mut fname = self.archive.path_starter(); fname.push(flydra_types::TEXTLOG_CSV_FNAME); diff --git a/ci2-pyloncxx/src/feature_cache.rs b/ci2-pyloncxx/src/feature_cache.rs index 49f3b3fa3..478fe782f 100644 --- a/ci2-pyloncxx/src/feature_cache.rs +++ b/ci2-pyloncxx/src/feature_cache.rs @@ -50,7 +50,7 @@ impl PfsCache { strict, }) } - pub(crate) fn to_string(&self) -> String { + pub(crate) fn to_header_string(&self) -> String { // Again, I could not find any documentation about the PFS (Pylon // Feature System) format, so this is all a guess. let mut out_lines = self.headers.clone(); @@ -62,7 +62,7 @@ impl PfsCache { pub(crate) fn update(&mut self, key: &str, value: String) { let mut found = false; for node in self.nodes.iter_mut() { - if &node.0 == key { + if node.0 == key { if found && self.strict { panic!("Key \"{}\" exists more than once in PFS.", key); } @@ -87,7 +87,7 @@ pub(crate) trait PfsTrackedIntegerNode { impl PfsTrackedIntegerNode for pylon_cxx::IntegerNode { fn set_value_pfs(&mut self, pfs: &mut PfsCache, new_value: i64) -> pylon_cxx::PylonResult<()> { self.set_value(new_value)?; - pfs.update(self.name(), format!("{}", new_value)); + pfs.update(self.name(), new_value.to_string()); Ok(()) } } @@ -99,7 +99,7 @@ pub(crate) trait PfsTrackedEnumNode { impl PfsTrackedEnumNode for pylon_cxx::EnumNode { fn set_value_pfs(&mut self, pfs: &mut PfsCache, new_value: &str) -> pylon_cxx::PylonResult<()> { self.set_value(new_value)?; - pfs.update(self.name(), format!("{}", new_value)); + pfs.update(self.name(), new_value.to_string()); Ok(()) } } diff --git a/ci2-pyloncxx/src/lib.rs b/ci2-pyloncxx/src/lib.rs index 40df766a8..47d18721b 100644 --- a/ci2-pyloncxx/src/lib.rs +++ b/ci2-pyloncxx/src/lib.rs @@ -96,11 +96,8 @@ impl Drop for PylonTerminateGuard { } } -pub fn make_singleton_guard<'a>( - _pylon_module: &dyn ci2::CameraModule< - CameraType = WrappedCamera<'a>, - Guard = PylonTerminateGuard, - >, +pub fn make_singleton_guard( + _pylon_module: &dyn ci2::CameraModule, ) -> ci2::Result { Ok(PylonTerminateGuard { already_dropped: false, @@ -331,14 +328,12 @@ impl<'a> WrappedCamera<'a> { store_fno: 0, last_rollover: 0, }) + } else if model == "Emulation" { + // As of Pylon 6.2.0, emulation with PYLON_CAMEMU does + // not set frame number. + FramecoutingMethod::IgnoreDevice(0) } else { - if model == "Emulation" { - // As of Pylon 6.2.0, emulation with PYLON_CAMEMU does - // not set frame number. - FramecoutingMethod::IgnoreDevice(0) - } else { - FramecoutingMethod::TrustDevice - } + FramecoutingMethod::TrustDevice }; let cam = tl_factory @@ -457,12 +452,12 @@ impl<'a> WrappedCamera<'a> { }); } } - return Err(Error::OtherError { + Err(Error::OtherError { msg: format!("requested camera '{}' was not found", name), #[cfg(feature = "backtrace")] backtrace: std::backtrace::Backtrace::capture(), } - .into()); + .into()) } fn exposure_time_param_name(&self) -> &'static str { @@ -623,7 +618,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { // Ideally we would simply call camera.node_map().map_pylon_err()?.save_to_string() here, // but this requires stopping the camera. Instead we cache the node // values. - Ok(self.pfs_cache.lock().to_string()) + Ok(self.pfs_cache.lock().to_header_string()) } /// Return the sensor width in pixels @@ -912,12 +907,10 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { match val.as_ref() { "Off" => Ok(ci2::TriggerMode::Off), "On" => Ok(ci2::TriggerMode::On), - s => { - return Err(ci2::Error::from(format!( - "unexpected TriggerMode enum string: {}", - s - ))); - } + s => Err(ci2::Error::from(format!( + "unexpected TriggerMode enum string: {}", + s + ))), } } fn set_trigger_mode(&mut self, value: TriggerMode) -> ci2::Result<()> { @@ -1002,12 +995,10 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { "FrameBurstStart" => Ok(ci2::TriggerSelector::FrameBurstStart), "FrameStart" => Ok(ci2::TriggerSelector::FrameStart), "ExposureActive" => Ok(ci2::TriggerSelector::ExposureActive), - s => { - return Err(ci2::Error::from(format!( - "unexpected TriggerSelector enum string: {}", - s - ))); - } + s => Err(ci2::Error::from(format!( + "unexpected TriggerSelector enum string: {}", + s + ))), } } fn set_trigger_selector(&mut self, value: TriggerSelector) -> ci2::Result<()> { @@ -1093,7 +1084,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { let cam = self.inner.lock(); // Wait for an image and then retrieve it. A timeout of 99999 ms is used. - cam.retrieve_result(99999, &mut *gr, pylon_cxx::TimeoutHandling::ThrowException) + cam.retrieve_result(99999, &mut gr, pylon_cxx::TimeoutHandling::ThrowException) .map_pylon_err()?; let now = chrono::Utc::now(); // earliest possible timestamp @@ -1246,12 +1237,10 @@ fn str_to_auto_mode(val: &str) -> ci2::Result { "Off" => Ok(ci2::AutoMode::Off), "Once" => Ok(ci2::AutoMode::Once), "Continuous" => Ok(ci2::AutoMode::Continuous), - s => { - return Err(ci2::Error::from(format!( - "unexpected AutoMode enum string: {}", - s - ))); - } + s => Err(ci2::Error::from(format!( + "unexpected AutoMode enum string: {}", + s + ))), } } diff --git a/ci2-remote-control/src/lib.rs b/ci2-remote-control/src/lib.rs index f4f4580bb..49652dcd8 100644 --- a/ci2-remote-control/src/lib.rs +++ b/ci2-remote-control/src/lib.rs @@ -382,7 +382,7 @@ impl std::fmt::Display for FfmpegCodecArgs { .codec .as_ref() .map(|c| format!("-c:v {c}")) - .unwrap_or_else(|| "".to_string()); + .unwrap_or_default(); let post = arg_fmt(self.post_codec_args.as_ref()); write!(f, "ffmpeg {pre} {codec} {post}") } diff --git a/flydra-feature-detector/src/lib.rs b/flydra-feature-detector/src/lib.rs index b316a6274..4849beb2a 100644 --- a/flydra-feature-detector/src/lib.rs +++ b/flydra-feature-detector/src/lib.rs @@ -648,7 +648,7 @@ impl FlydraFeatureDetector { // the camera driver. acquire_stamp.as_f64() - trigger_stamp.as_f64() } - None => std::f64::NAN, + None => f64::NAN, }; self.acquisition_histogram diff --git a/flydra-types/src/lib.rs b/flydra-types/src/lib.rs index 6747bc2e3..81a21b508 100644 --- a/flydra-types/src/lib.rs +++ b/flydra-types/src/lib.rs @@ -859,8 +859,8 @@ impl Sorted { Sorted(vals) } fn dist_and_argmin(&self, x: f64) -> (f64, usize) { - let mut best_dist = std::f64::INFINITY; - let mut prev_dist = std::f64::INFINITY; + let mut best_dist = f64::INFINITY; + let mut prev_dist = f64::INFINITY; let mut best_idx = 0; for (i, selfi) in self.0.iter().enumerate() { let dist = (selfi - x).abs(); @@ -1358,7 +1358,7 @@ where // TODO: should match on DeserializeError with empty field only, // otherwise, return error. The way this is written, anything // will return a nan. - Ok(std::f64::NAN), + Ok(f64::NAN), ) } diff --git a/flydra-types/src/timestamp.rs b/flydra-types/src/timestamp.rs index 4c32b54b1..9c8c13534 100644 --- a/flydra-types/src/timestamp.rs +++ b/flydra-types/src/timestamp.rs @@ -124,7 +124,7 @@ pub fn triggerbox_time( #[test] #[should_panic] fn test_nan_handling() { - let _ts = FlydraFloatTimestampLocal::::from_f64(std::f64::NAN); + let _ts = FlydraFloatTimestampLocal::::from_f64(f64::NAN); } /// Ensure that conversion with particular floating point representation remains diff --git a/flydra-types/src/timestamp_opt_f64.rs b/flydra-types/src/timestamp_opt_f64.rs index 6359617ab..74dfd2254 100644 --- a/flydra-types/src/timestamp_opt_f64.rs +++ b/flydra-types/src/timestamp_opt_f64.rs @@ -21,7 +21,7 @@ where { let val = match orig { Some(ref tl) => tl.as_f64(), - None => std::f64::NAN, + None => f64::NAN, }; serializer.serialize_f64(val) } diff --git a/flydra2/src/connected_camera_manager.rs b/flydra2/src/connected_camera_manager.rs index dc60d672f..c6391da88 100644 --- a/flydra2/src/connected_camera_manager.rs +++ b/flydra2/src/connected_camera_manager.rs @@ -347,7 +347,7 @@ impl ConnectedCamerasManager { inner.ccis.insert( raw_cam_name.clone(), ConnectedCameraInfo { - cam_num: cam_num.clone(), + cam_num, raw_cam_name: raw_cam_name.clone(), sync_state: ConnectedCameraSyncState::Unsynchronized, http_camserver_info: http_camserver_info.clone(), @@ -389,13 +389,7 @@ impl ConnectedCamerasManager { TriggerType::FakeSync(_) => { self.got_new_frame_live_triggerbox(packet, sync_pulse_pause_started_arc, 0) } - TriggerType::PtpSync(ptpcfg) => { - if let Some(sync_data) = self.got_new_frame_live_ptp(packet, ptpcfg) { - sync_data - } else { - return None; - } - } + TriggerType::PtpSync(ptpcfg) => self.got_new_frame_live_ptp(packet, ptpcfg)?, TriggerType::DeviceTimestamp => { todo!(); } diff --git a/flydra2/src/flydra2.rs b/flydra2/src/flydra2.rs index e1c144e46..50e9bb77b 100644 --- a/flydra2/src/flydra2.rs +++ b/flydra2/src/flydra2.rs @@ -355,13 +355,13 @@ impl FrameDataAndPoints { } fn safe_u8(val: usize) -> u8 { - assert!(val <= u8::max_value() as usize, "value out of range"); + assert!(val <= u8::MAX as usize, "value out of range"); val as u8 } fn convert_to_save(frame_data: &FrameData, input: &NumberedRawUdpPoint) -> Data2dDistortedRowF32 { let (slope, eccentricity) = match input.pt.maybe_slope_eccentricty { - None => (std::f32::NAN, std::f32::NAN), + None => (f32::NAN, f32::NAN), Some((s, e)) => (s as f32, e as f32), }; @@ -392,15 +392,15 @@ fn convert_empty_to_save(frame_data: &FrameData) -> Data2dDistortedRowF32 { cam_received_timestamp: frame_data.cam_received_timestamp.clone(), device_timestamp: frame_data.device_timestamp, block_id: frame_data.block_id, - x: std::f32::NAN, - y: std::f32::NAN, - area: std::f32::NAN, - slope: std::f32::NAN, - eccentricity: std::f32::NAN, + x: f32::NAN, + y: f32::NAN, + area: f32::NAN, + slope: f32::NAN, + eccentricity: f32::NAN, frame_pt_idx: 0, cur_val: 0, - mean_val: std::f32::NAN, - sumsqf_val: std::f32::NAN, + mean_val: f32::NAN, + sumsqf_val: f32::NAN, } } @@ -1041,8 +1041,8 @@ fn test_csv_nan() { cam_received_timestamp: FlydraFloatTimestampLocal::from_dt(&chrono::Local::now()), device_timestamp: None, block_id: None, - x: std::f32::NAN, - y: std::f32::NAN, + x: f32::NAN, + y: f32::NAN, area: 1.0, slope: 2.0, eccentricity: 3.0, diff --git a/flydra2/src/mini_arenas.rs b/flydra2/src/mini_arenas.rs index bfa95ed9f..314d429a4 100644 --- a/flydra2/src/mini_arenas.rs +++ b/flydra2/src/mini_arenas.rs @@ -112,13 +112,15 @@ pub(crate) fn build_mini_arena_images( let frame = machine_vision_formats::owned::OImage::::new( cam.width().try_into().unwrap(), cam.height().try_into().unwrap(), - cam.width().try_into().unwrap(), + cam.width(), mini_arena_image.clone(), ) .unwrap(); - let png_buf = - convert_image::frame_to_encoded_buffer(&frame, convert_image::EncoderOptions::Png) - .unwrap(); + let png_buf = convert_image::frame_to_encoded_buffer( + &frame, + convert_image::EncoderOptions::Png, + ) + .unwrap(); let dest_path = PathBuf::from(dest_dir).join(format!("mini_arenas_{}.png", cam.name())); diff --git a/flydra2/src/model_server.rs b/flydra2/src/model_server.rs index 8a7697ade..f6638cc3a 100644 --- a/flydra2/src/model_server.rs +++ b/flydra2/src/model_server.rs @@ -191,10 +191,9 @@ pub async fn new_model_server( .next() .unwrap(); tracing::info!("Streaming data to rerun at {socket_addr}"); - let rec = rerun::RecordingStreamBuilder::new("braid") + rerun::RecordingStreamBuilder::new("braid") .connect_tcp_opts(socket_addr, None) - .unwrap(); - rec + .unwrap() }); if rec.is_none() { @@ -256,7 +255,7 @@ fn get_body(data: &(SendType, TimeDataPassthrough)) -> String { let now_f64 = datetime_conversion::datetime_to_f64(&chrono::Local::now()); now_f64 - tt.as_f64() } else { - std::f64::NAN + f64::NAN }; // Send updates after each observation for lowest-possible latency. diff --git a/flytrax-csv-to-braidz/src/lib.rs b/flytrax-csv-to-braidz/src/lib.rs index 8ddcef027..bd094f16e 100644 --- a/flytrax-csv-to-braidz/src/lib.rs +++ b/flytrax-csv-to-braidz/src/lib.rs @@ -452,11 +452,11 @@ fn convert_row( ) -> Data2dDistortedRow { let (eccentricity, slope) = match strand_cam_row.orientation_radians_mod_pi { Some(angle) => (1.1, angle.tan()), - None => (std::f64::NAN, std::f64::NAN), + None => (f64::NAN, f64::NAN), }; let frame_pt_idx = row_state.update(strand_cam_row.frame); Data2dDistortedRow { - area: strand_cam_row.central_moment.unwrap_or(std::f64::NAN), + area: strand_cam_row.central_moment.unwrap_or(f64::NAN), cam_received_timestamp: get_timestamp(&strand_cam_row, ts0), device_timestamp: None, block_id: None, @@ -465,9 +465,9 @@ fn convert_row( frame: strand_cam_row.frame, eccentricity, frame_pt_idx, - mean_val: std::f64::NAN, + mean_val: f64::NAN, slope, - sumsqf_val: std::f64::NAN, + sumsqf_val: f64::NAN, timestamp: None, //flydra_types::FlydraFloatTimestampLocal::from_dt(&dt), x: strand_cam_row.x_px, y: strand_cam_row.y_px, diff --git a/freemovr-calibration/src/lib.rs b/freemovr-calibration/src/lib.rs index c9c805589..525e1f5e9 100644 --- a/freemovr-calibration/src/lib.rs +++ b/freemovr-calibration/src/lib.rs @@ -471,13 +471,13 @@ pub trait DisplayGeometry { // Some(tc) => Computed::TexCoords((tc[0],tc[1])), // None => { // panic!("no intersection but TOI: {:?}", surface_pt); - // // Computed::TexCoords((std::f64::NAN,std::f64::NAN)) + // // Computed::TexCoords((f64::NAN,f64::NAN)) // }, // } let tc = ray_intersect.uvs.unwrap(); // we know we have uvs for our shapes, so unwrap() is ok Computed::TexCoords((tc[0], tc[1])) } - None => Computed::TexCoords((std::f64::NAN, std::f64::NAN)), + None => Computed::TexCoords((f64::NAN, f64::NAN)), } } } @@ -508,7 +508,7 @@ pub fn compute_image_for_camera_view( Computable::TexCoords => 2, // U, V }; - let mut result = vec![std::f64::NAN; cam.width() * cam.height() * nchan]; + let mut result = vec![f64::NAN; cam.width() * cam.height() * nchan]; // println!("-------- CAMERA"); // println!("pmat {}", pretty_print_nalgebra::pretty_print!(cam.as_pmat().unwrap())); diff --git a/media-utils/ffmpeg-writer/src/lib.rs b/media-utils/ffmpeg-writer/src/lib.rs index ad12739ef..98e54b7e5 100644 --- a/media-utils/ffmpeg-writer/src/lib.rs +++ b/media-utils/ffmpeg-writer/src/lib.rs @@ -49,14 +49,13 @@ fn middle() -> Vec { } fn zq(x: &[&str]) -> Vec { - x.into_iter().map(|x| (*x).into()).collect() + x.iter().map(|x| (*x).into()).collect() } fn zq2(opt_x: Option<&Vec<(String, String)>>) -> Vec { if let Some(x) = opt_x { - x.into_iter() - .map(|(x1, x2)| [x1.clone(), x2.clone()]) - .flatten() + x.iter() + .flat_map(|(x1, x2)| [x1.clone(), x2.clone()]) .collect() } else { vec![] @@ -74,7 +73,7 @@ impl FfmpegCodecArgs { zq2(self.device_args.as_ref()), middle(), zq2(self.pre_codec_args.as_ref()), - zq(&[VIDEO_CODEC, &codec]), + zq(&[VIDEO_CODEC, codec]), zq2(self.post_codec_args.as_ref()), ] } else { diff --git a/media-utils/y4m-writer/src/lib.rs b/media-utils/y4m-writer/src/lib.rs index f54208a72..8cd2df6ee 100644 --- a/media-utils/y4m-writer/src/lib.rs +++ b/media-utils/y4m-writer/src/lib.rs @@ -102,7 +102,7 @@ impl Y4MWriter { let this_width: usize = frame.width().try_into().unwrap(); let this_height: usize = frame.height().try_into().unwrap(); - let info = self.info.get_or_insert_with(|| Y4MInfo { + let info = self.info.get_or_insert(Y4MInfo { width: this_width, height: this_height, fmt: this_fmt, @@ -130,7 +130,7 @@ impl Y4MWriter { y4m::Ratio::new(self.opts.raten, self.opts.rated), ) .with_pixel_aspect(y4m::Ratio::new(self.opts.aspectn, self.opts.aspectd)) - .with_colorspace(colorspace.into()) + .with_colorspace(colorspace) .append_vendor_extension(y4m::VendorExtensionString::new( b"COLORRANGE=FULL".into(), )?); @@ -237,14 +237,10 @@ pub struct Y4MFrame { forced_block_size: Option, } -impl<'a> Into> for &'a Y4MFrame { - fn into(self) -> y4m::Frame<'a> { - y4m::Frame::new( - [ - self.y_plane_data(), - self.u_plane_data(), - self.v_plane_data(), - ], +impl<'a> From<&'a Y4MFrame> for y4m::Frame<'a> { + fn from(val: &'a Y4MFrame) -> Self { + Self::new( + [val.y_plane_data(), val.u_plane_data(), val.v_plane_data()], None, ) } @@ -728,9 +724,7 @@ where } } } - cs => { - return Err(Error::UnsupportedColorspace(cs)); - } + cs => Err(Error::UnsupportedColorspace(cs)), } } diff --git a/strand-cam/src/cli_app.rs b/strand-cam/src/cli_app.rs index 882e39d66..0e4d489df 100644 --- a/strand-cam/src/cli_app.rs +++ b/strand-cam/src/cli_app.rs @@ -29,7 +29,7 @@ where ); } - let args = parse_args(app_name).with_context(|| format!("parsing args"))?; + let args = parse_args(app_name).with_context(|| "parsing args".to_string())?; run_strand_cam_app(mymod, args, app_name) } diff --git a/strand-cam/src/datagram_socket.rs b/strand-cam/src/datagram_socket.rs index 4d14d6ff1..509af37ac 100644 --- a/strand-cam/src/datagram_socket.rs +++ b/strand-cam/src/datagram_socket.rs @@ -9,7 +9,7 @@ pub(crate) trait SendComplete { impl SendComplete for UdpSocket { fn send_complete(&self, x: &[u8]) -> Result<()> { - match self.send(&x) { + match self.send(x) { Ok(sz) => { if sz != x.len() { eyre::bail!("incomplete send"); diff --git a/strand-cam/src/frame_process_task.rs b/strand-cam/src/frame_process_task.rs index 88b219fff..cdcfa4930 100644 --- a/strand-cam/src/frame_process_task.rs +++ b/strand-cam/src/frame_process_task.rs @@ -1020,7 +1020,7 @@ pub(crate) async fn frame_process_task<'a>( }) .enumerate() .map(|(i, pt)| { - assert!(i <= u8::max_value() as usize); + assert!(i <= u8::MAX as usize); let idx = i as u8; flydra2::NumberedRawUdpPoint { idx, diff --git a/strand-cam/src/strand-cam.rs b/strand-cam/src/strand-cam.rs index 8933133ef..9abbd9238 100644 --- a/strand-cam/src/strand-cam.rs +++ b/strand-cam/src/strand-cam.rs @@ -251,19 +251,14 @@ impl std::fmt::Debug for Msg { } } -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Default)] pub enum FrameProcessingErrorState { + #[default] NotifyAll, IgnoreUntil(chrono::DateTime), IgnoreAll, } -impl Default for FrameProcessingErrorState { - fn default() -> Self { - FrameProcessingErrorState::NotifyAll - } -} - #[cfg(feature = "flydra_feat_detect")] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub enum Tracker { @@ -1564,11 +1559,8 @@ where }; #[cfg(not(feature = "flydra_feat_detect"))] - match &res_braid { - Ok(bi) => { - let _ = bi.tracker_cfg_src.clone(); // silence unused field warning. - } - Err(_) => {} + if let Ok(bi) = &res_braid { + let _ = bi.tracker_cfg_src.clone(); // silence unused field warning. }; // Here we just create some default, it does not matter what, because it @@ -1601,7 +1593,7 @@ where }; let camdata_udp_addr = match &res_braid { - Ok(bi) => Some(bi.camdata_udp_addr.clone()), + Ok(bi) => Some(bi.camdata_udp_addr), Err(_a) => None, }; @@ -2198,6 +2190,7 @@ where } #[cfg(not(feature = "eframe-gui"))] + #[allow(clippy::let_unit_value)] let _ = gui_singleton; // Display where we are listening. @@ -2208,7 +2201,7 @@ where for url in urls.iter() { info!(" * predicted URL {url}"); - if !flydra_types::is_loopback(&url) { + if !flydra_types::is_loopback(url) { println!("QR code for {url}"); display_qr_url(&format!("{url}")); } @@ -3299,7 +3292,7 @@ where if !no_browser { tokio::spawn(async move { // Let the webserver start before opening browser. - let _ = launched_rx.changed().await.unwrap(); + launched_rx.changed().await.unwrap(); open_browser(format!("{}", urls[0])).unwrap(); }); } @@ -3651,7 +3644,7 @@ fn bitrate_to_u32(br: &ci2_remote_control::BitrateSelection) -> u32 { Bitrate4000 => 4000, Bitrate5000 => 5000, Bitrate10000 => 10000, - BitrateUnlimited => std::u32::MAX, + BitrateUnlimited => u32::MAX, } } diff --git a/strand-cam/yew_frontend/src/components/video_field.rs b/strand-cam/yew_frontend/src/components/video_field.rs index 990b23a90..017c713d7 100644 --- a/strand-cam/yew_frontend/src/components/video_field.rs +++ b/strand-cam/yew_frontend/src/components/video_field.rs @@ -179,8 +179,7 @@ impl Component for VideoField { Msg::NotifySender => { self.timeout = None; if let Some(ref callback) = ctx.props().on_rendered { - let ck = self.ck.clone(); - callback.emit(ck); + callback.emit(self.ck); } } Msg::ViewFitWidth => { diff --git a/strand-cam/yew_frontend/src/lib.rs b/strand-cam/yew_frontend/src/lib.rs index b21a877ea..6e3b21425 100644 --- a/strand-cam/yew_frontend/src/lib.rs +++ b/strand-cam/yew_frontend/src/lib.rs @@ -1406,11 +1406,7 @@ trait HasAvail { impl HasAvail for ServerState { fn available_codecs(&self) -> Vec { - let have_nvenc = if !self.cuda_devices.is_empty() && self.is_nvenc_functioning { - true - } else { - false - }; + let have_nvenc = !self.cuda_devices.is_empty() && self.is_nvenc_functioning; let result = CodecSelection::variants().to_vec(); @@ -1425,16 +1421,14 @@ impl HasAvail for ServerState { }; // Remove videotoolbox codec if we do not have videotoolbox available. - let result = if !self.is_videotoolbox_functioning { + if !self.is_videotoolbox_functioning { result .into_iter() .filter(|x| !x.requires("videotoolbox")) .collect() } else { result - }; - - result + } } } diff --git a/tracking/src/observation_model_2d.rs b/tracking/src/observation_model_2d.rs index 16dbf669e..76512b7c2 100644 --- a/tracking/src/observation_model_2d.rs +++ b/tracking/src/observation_model_2d.rs @@ -53,6 +53,6 @@ where &self.observation_noise_covariance } fn predict_observation(&self, state: &OVector) -> OVector { - &self.observation_matrix * state + self.observation_matrix * state } }