Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
refactor(rust): apply clippy lint fixes across crates
Richie McIlroy0fa1184d0205
diff --git a/crates/cap-test/src/suites/encoding.rs b/crates/cap-test/src/suites/encoding.rsindex bc4d2e4d8..74cf40734 100644--- a/crates/cap-test/src/suites/encoding.rs+++ b/crates/cap-test/src/suites/encoding.rs@@ -128,8 +128,8 @@ async fn run_encoding_benchmark(frames_processed += 1;let elapsed = frame_start.elapsed();- if elapsed < frame_interval {- tokio::time::sleep(frame_interval - elapsed).await;+ if let Some(remaining) = frame_interval.checked_sub(elapsed) {+ tokio::time::sleep(remaining).await;}}diff --git a/crates/cap-test/src/suites/playback.rs b/crates/cap-test/src/suites/playback.rsindex 42a5aaf1e..4764c0e50 100644--- a/crates/cap-test/src/suites/playback.rs+++ b/crates/cap-test/src/suites/playback.rs@@ -125,8 +125,8 @@ async fn run_playback_test(width: u32, height: u32, duration_secs: u64) -> Resul}let elapsed = frame_start.elapsed();- if elapsed < frame_interval {- tokio::time::sleep(frame_interval - elapsed).await;+ if let Some(remaining) = frame_interval.checked_sub(elapsed) {+ tokio::time::sleep(remaining).await;}}diff --git a/crates/cap-test/src/suites/recording.rs b/crates/cap-test/src/suites/recording.rsindex ecf5fe0c1..9ce320c94 100644--- a/crates/cap-test/src/suites/recording.rs+++ b/crates/cap-test/src/suites/recording.rs@@ -190,7 +190,13 @@ impl RecordingTestRunner {completed.project_path.display());- let frames_encoded = completed.display_frame_count;+ let validation = super::validate::validate_recording(&completed.project_path).await?;++ let frames_encoded = validation+ .video_info+ .as_ref()+ .map(|v| v.frame_count)+ .unwrap_or(expected_frames);let frames_received = expected_frames;let frames_dropped = if frames_received > frames_encoded {frames_received - frames_encoded@@ -205,8 +211,6 @@ impl RecordingTestRunner {};let actual_duration = total_duration.as_secs_f64();- let validation = super::validate::validate_recording(&completed.project_path).await?;-let frame_time_ms = if actual_fps > 0.0 {1000.0 / actual_fps} else {@@ -237,12 +241,12 @@ impl RecordingTestRunner {warn!("Validation warning: {}", warning);}- if let Some(ref sync) = validation.sync_info {- if !sync.in_sync {- metrics- .errors- .push(format!("A/V drift too high: {:.1}ms", sync.drift_ms));- }+ if let Some(ref sync) = validation.sync_info+ && !sync.in_sync+ {+ metrics+ .errors+ .push(format!("A/V drift too high: {:.1}ms", sync.drift_ms));}info!(@@ -308,8 +312,8 @@ impl RecordingTestRunner {}let elapsed = frame_start.elapsed();- if elapsed < frame_interval {- tokio::time::sleep(frame_interval - elapsed).await;+ if let Some(remaining) = frame_interval.checked_sub(elapsed) {+ tokio::time::sleep(remaining).await;}}diff --git a/crates/cap-test/src/suites/sync.rs b/crates/cap-test/src/suites/sync.rsindex 069d42b18..d3be6edaa 100644--- a/crates/cap-test/src/suites/sync.rs+++ b/crates/cap-test/src/suites/sync.rs@@ -164,8 +164,8 @@ async fn run_sync_test(fps: u32, duration_secs: u64) -> Result<SyncTestMetrics>drifts.push(drift);let elapsed = frame_start.elapsed();- if elapsed < frame_interval {- tokio::time::sleep(frame_interval - elapsed).await;+ if let Some(remaining) = frame_interval.checked_sub(elapsed) {+ tokio::time::sleep(remaining).await;}}diff --git a/crates/cap-test/src/suites/validate.rs b/crates/cap-test/src/suites/validate.rsindex 788ae3453..7697be09c 100644--- a/crates/cap-test/src/suites/validate.rs+++ b/crates/cap-test/src/suites/validate.rs@@ -191,26 +191,24 @@ async fn validate_cap_project(fps = parse_frame_rate(rate);}}- if let Some(ref dur) = stream.duration {- if let Ok(d) = dur.parse::<f64>() {- total_duration += d;- }+ if let Some(ref dur) = stream.duration+ && let Ok(d) = dur.parse::<f64>()+ {+ total_duration += d;}- if let Some(ref frames) = stream.nb_frames {- if let Ok(f) = frames.parse::<u64>() {- total_frames += f;- }+ if let Some(ref frames) = stream.nb_frames+ && let Ok(f) = frames.parse::<u64>()+ {+ total_frames += f;}}}- if total_duration == 0.0 {- if let Some(ref format) = probe.format {- if let Some(ref dur) = format.duration {- if let Ok(d) = dur.parse::<f64>() {- total_duration += d;- }- }- }+ if total_duration == 0.0+ && let Some(ref format) = probe.format+ && let Some(ref dur) = format.duration+ && let Ok(d) = dur.parse::<f64>()+ {+ total_duration += d;}}Err(e) => {@@ -349,7 +347,7 @@ async fn validate_video_file(.nb_frames.as_ref().and_then(|f| f.parse::<u64>().ok())- .unwrap_or_else(|| (duration * fps) as u64);+ .unwrap_or((duration * fps) as u64);video_start_time = stream.start_timediff --git a/crates/enc-avfoundation/src/mp4.rs b/crates/enc-avfoundation/src/mp4.rsindex 0f2a46712..666cd89d0 100644--- a/crates/enc-avfoundation/src/mp4.rs+++ b/crates/enc-avfoundation/src/mp4.rs@@ -665,7 +665,7 @@ fn duration_to_timescale_value(duration: Duration, timescale: i32) -> i64 {fn timescale_value_to_duration(value: i64, timescale: i32) -> Duration {let scale = timescale.max(1) as u128;- let v = u128::try_from(value.max(0) as u64).unwrap_or(0);+ let v = u128::from(value.max(0) as u64);let nanos = (v.saturating_mul(1_000_000_000u128) / scale).min(u64::MAX as u128) as u64;Duration::from_nanos(nanos)}diff --git a/crates/frame-converter/examples/benchmark.rs b/crates/frame-converter/examples/benchmark.rsindex 4449274b1..a606d1266 100644--- a/crates/frame-converter/examples/benchmark.rs+++ b/crates/frame-converter/examples/benchmark.rs@@ -242,11 +242,7 @@ fn simulate_realtime_pipeline(println!(" Total encode time: {encode_time_total:?}");let expected_duration = Duration::from_secs_f64(total_frames as f64 / target_fps);- let overhead = if elapsed > expected_duration {- elapsed - expected_duration- } else {- Duration::ZERO- };+ let overhead = elapsed.saturating_sub(expected_duration);println!(" Processing overhead: {overhead:?}");if stats.frames_dropped == 0 {diff --git a/crates/recording/examples/real-device-test-runner.rs b/crates/recording/examples/real-device-test-runner.rsindex 797aedaa8..c2b0ef3d2 100644--- a/crates/recording/examples/real-device-test-runner.rs+++ b/crates/recording/examples/real-device-test-runner.rs@@ -721,54 +721,51 @@ fn validate_segment_timing(meta: &RecordingMeta) -> SegmentTimingValidation {if let StudioRecordingMeta::MultipleSegments { inner } = studio_meta.as_ref() {for (idx, segment) in inner.segments.iter().enumerate() {- if let Some(start_time) = segment.display.start_time {- if start_time.abs() > START_TIME_THRESHOLD {- result.all_valid = false;- result.issues.push(SegmentTimingIssue {- segment_index: idx,- stream_type: "display".to_string(),- start_time,- });- }+ if let Some(start_time) = segment.display.start_time+ && start_time.abs() > START_TIME_THRESHOLD+ {+ result.all_valid = false;+ result.issues.push(SegmentTimingIssue {+ segment_index: idx,+ stream_type: "display".to_string(),+ start_time,+ });}- if let Some(ref mic) = segment.mic {- if let Some(start_time) = mic.start_time {- if start_time.abs() > START_TIME_THRESHOLD {- result.all_valid = false;- result.issues.push(SegmentTimingIssue {- segment_index: idx,- stream_type: "mic".to_string(),- start_time,- });- }- }+ if let Some(ref mic) = segment.mic+ && let Some(start_time) = mic.start_time+ && start_time.abs() > START_TIME_THRESHOLD+ {+ result.all_valid = false;+ result.issues.push(SegmentTimingIssue {+ segment_index: idx,+ stream_type: "mic".to_string(),+ start_time,+ });}- if let Some(ref camera) = segment.camera {- if let Some(start_time) = camera.start_time {- if start_time.abs() > START_TIME_THRESHOLD {- result.all_valid = false;- result.issues.push(SegmentTimingIssue {- segment_index: idx,- stream_type: "camera".to_string(),- start_time,- });- }- }+ if let Some(ref camera) = segment.camera+ && let Some(start_time) = camera.start_time+ && start_time.abs() > START_TIME_THRESHOLD+ {+ result.all_valid = false;+ result.issues.push(SegmentTimingIssue {+ segment_index: idx,+ stream_type: "camera".to_string(),+ start_time,+ });}- if let Some(ref system_audio) = segment.system_audio {- if let Some(start_time) = system_audio.start_time {- if start_time.abs() > START_TIME_THRESHOLD {- result.all_valid = false;- result.issues.push(SegmentTimingIssue {- segment_index: idx,- stream_type: "system_audio".to_string(),- start_time,- });- }- }+ if let Some(ref system_audio) = segment.system_audio+ && let Some(start_time) = system_audio.start_time+ && start_time.abs() > START_TIME_THRESHOLD+ {+ result.all_valid = false;+ result.issues.push(SegmentTimingIssue {+ segment_index: idx,+ stream_type: "system_audio".to_string(),+ start_time,+ });}}}@@ -866,11 +863,11 @@ fn analyze_frame_rate_for_file(let mut ictx = ffmpeg::format::input(path)?;for (stream, packet) in ictx.packets() {- if stream.index() == stream_index {- if let Some(pts) = packet.pts() {- let timestamp_secs = pts as f64 * time_base_secs;- frame_timestamps.push(timestamp_secs);- }+ if stream.index() == stream_index+ && let Some(pts) = packet.pts()+ {+ let timestamp_secs = pts as f64 * time_base_secs;+ frame_timestamps.push(timestamp_secs);}}@@ -1090,12 +1087,12 @@ fn analyze_audio_stream(let mut ictx = ffmpeg::format::input(path)?;for (stream, packet) in ictx.packets() {- if stream.index() == stream_index {- if let (Some(pts), Some(duration)) = (packet.pts(), Some(packet.duration())) {- let start_secs = pts as f64 * time_base_secs;- let dur_secs = duration as f64 * time_base_secs;- packet_timestamps.push((start_secs, dur_secs));- }+ if stream.index() == stream_index+ && let Some(pts) = packet.pts()+ {+ let start_secs = pts as f64 * time_base_secs;+ let dur_secs = packet.duration() as f64 * time_base_secs;+ packet_timestamps.push((start_secs, dur_secs));}}@@ -1678,10 +1675,10 @@ async fn main() -> anyhow::Result<()> {let include_camera = !cli.no_camera && !devices.cameras.is_empty();- if cli.output_dir.exists() {- if let Err(e) = std::fs::remove_dir_all(&cli.output_dir) {- tracing::warn!("Failed to clean output directory: {}", e);- }+ if cli.output_dir.exists()+ && let Err(e) = std::fs::remove_dir_all(&cli.output_dir)+ {+ tracing::warn!("Failed to clean output directory: {}", e);}std::fs::create_dir_all(&cli.output_dir)?;diff --git a/crates/recording/examples/synthetic-test-runner.rs b/crates/recording/examples/synthetic-test-runner.rsindex b645d8de3..f2ec2c355 100644--- a/crates/recording/examples/synthetic-test-runner.rs+++ b/crates/recording/examples/synthetic-test-runner.rs@@ -135,10 +135,10 @@ async fn main() {let mut failed = 0;let mut results = Vec::new();- if cli.output_dir.exists() {- if let Err(e) = std::fs::remove_dir_all(&cli.output_dir) {- tracing::warn!("Failed to clean output directory before tests: {}", e);- }+ if cli.output_dir.exists()+ && let Err(e) = std::fs::remove_dir_all(&cli.output_dir)+ {+ tracing::warn!("Failed to clean output directory before tests: {}", e);}let start = Instant::now();@@ -204,10 +204,10 @@ async fn main() {println!("\nReport saved to: {}", report_path.display());}- if !cli.keep_outputs {- if let Err(e) = std::fs::remove_dir_all(&cli.output_dir) {- tracing::warn!("Failed to clean up output directory: {}", e);- }+ if !cli.keep_outputs+ && let Err(e) = std::fs::remove_dir_all(&cli.output_dir)+ {+ tracing::warn!("Failed to clean up output directory: {}", e);}std::process::exit(if failed > 0 { 1 } else { 0 });diff --git a/crates/recording/src/instant_recording.rs b/crates/recording/src/instant_recording.rsindex 6c9923467..5b430c808 100644--- a/crates/recording/src/instant_recording.rs+++ b/crates/recording/src/instant_recording.rs@@ -403,7 +403,7 @@ pub async fn spawn_instant_recording_actor(.await.context("camera-only pipeline setup")?;- let video_info = camera_feed.video_info().clone();+ let video_info = *camera_feed.video_info();(Pipeline {output: pipeline,diff --git a/crates/recording/src/studio_recording.rs b/crates/recording/src/studio_recording.rsindex 4e43a3519..f6cebdb58 100644--- a/crates/recording/src/studio_recording.rs+++ b/crates/recording/src/studio_recording.rs@@ -1195,9 +1195,7 @@ async fn create_segment_pipeline(None};- let cursor_display = cursor_display- .clone()- .ok_or(CreateSegmentPipelineError::NoDisplay)?;+ let cursor_display = cursor_display.ok_or(CreateSegmentPipelineError::NoDisplay)?;let cursor = spawn_cursor_recorder(cursor_crop_bounds,diff --git a/crates/rendering/src/cpu_yuv.rs b/crates/rendering/src/cpu_yuv.rsindex ea929e535..0207e4602 100644--- a/crates/rendering/src/cpu_yuv.rs+++ b/crates/rendering/src/cpu_yuv.rs@@ -1123,9 +1123,9 @@ mod tests {let y_stride = 1920u32;let uv_stride = 1920u32;- let y_data: Vec<u8> = (0..y_stride * height).map(|i| ((i % 256) as u8)).collect();+ let y_data: Vec<u8> = (0..y_stride * height).map(|i| (i % 256) as u8).collect();let uv_data: Vec<u8> = (0..uv_stride * height / 2)- .map(|i| (((i + 64) % 256) as u8))+ .map(|i| ((i + 64) % 256) as u8).collect();let mut output = vec![0u8; (width * height * 4) as usize];diff --git a/crates/rendering/src/decoder/avassetreader.rs b/crates/rendering/src/decoder/avassetreader.rsindex 53d2c9337..73f9c62a4 100644--- a/crates/rendering/src/decoder/avassetreader.rs+++ b/crates/rendering/src/decoder/avassetreader.rs@@ -894,7 +894,7 @@ mod tests {assert_eq!(health.consecutive_empty_iterations, 0);assert_eq!(health.consecutive_errors, 0);assert_eq!(health.total_frames_decoded, 0);- assert!(!health.needs_recreation());+ assert!(!health.needs_recreation(0, 100));}#[test]@@ -903,12 +903,12 @@ mod tests {health.consecutive_empty_iterations = 3;health.consecutive_errors = 5;- health.record_success(10);+ health.record_success(10, 9);assert_eq!(health.consecutive_empty_iterations, 0);assert_eq!(health.consecutive_errors, 0);assert_eq!(health.total_frames_decoded, 10);- assert!(!health.needs_recreation());+ assert!(!health.needs_recreation(10, 100));}#[test]@@ -917,7 +917,7 @@ mod tests {for _ in 0..DecoderHealth::MAX_CONSECUTIVE_EMPTY {health.record_empty_iteration();}- assert!(health.needs_recreation());+ assert!(health.needs_recreation(50, 100));}#[test]@@ -926,7 +926,7 @@ mod tests {for _ in 0..DecoderHealth::MAX_CONSECUTIVE_ERRORS {health.record_error();}- assert!(health.needs_recreation());+ assert!(health.needs_recreation(50, 100));}#[test]@@ -939,7 +939,7 @@ mod tests {assert_eq!(health.consecutive_empty_iterations, 0);assert_eq!(health.consecutive_errors, 0);- assert!(!health.needs_recreation());+ assert!(!health.needs_recreation(0, 100));}#[test]@@ -948,6 +948,6 @@ mod tests {for _ in 0..(DecoderHealth::MAX_CONSECUTIVE_EMPTY - 1) {health.record_empty_iteration();}- assert!(!health.needs_recreation());+ assert!(!health.needs_recreation(50, 100));}}diff --git a/crates/rendering/src/decoder/ffmpeg.rs b/crates/rendering/src/decoder/ffmpeg.rsindex 9c268f2c4..c664f7a5b 100644--- a/crates/rendering/src/decoder/ffmpeg.rs+++ b/crates/rendering/src/decoder/ffmpeg.rs@@ -252,9 +252,6 @@ impl FfmpegDecoder {let first_frame_result = (&mut frames).flatten().next();if first_frame_result.is_none() && is_hw {- drop(frames);- drop(this);-let mut sw_this = match cap_video_decode::FFmpegDecoder::new(path.clone(), None) {Err(e) => {let _ = continue_tx.send(Err(format!("Software fallback failed: {e}")));diff --git a/crates/scap-ffmpeg/examples/cli.rs b/crates/scap-ffmpeg/examples/cli.rsindex 883dee1a0..12aa005c2 100644--- a/crates/scap-ffmpeg/examples/cli.rs+++ b/crates/scap-ffmpeg/examples/cli.rs@@ -82,11 +82,11 @@ pub async fn main() {.build().expect("Failed to build capturer");- block_on(capturer.start()).expect("Failed to start capturing");+ capturer.start().await.expect("Failed to start capturing");std::thread::sleep(Duration::from_secs(3));- block_on(capturer.stop()).expect("Failed to stop capturing");+ capturer.stop().await.expect("Failed to stop capturing");std::thread::sleep(Duration::from_secs(1));}diff --git a/crates/scap-screencapturekit/examples/cli.rs b/crates/scap-screencapturekit/examples/cli.rsindex 9be41ceb7..d70849e78 100644--- a/crates/scap-screencapturekit/examples/cli.rs+++ b/crates/scap-screencapturekit/examples/cli.rs@@ -44,11 +44,11 @@ mod macos {.build().expect("Failed to build capturer");- block_on(capturer.start()).expect("Failed to start capturing");+ capturer.start().await.expect("Failed to start capturing");std::thread::sleep(Duration::from_secs(3));- block_on(capturer.stop()).expect("Failed to stop capturing");+ capturer.stop().await.expect("Failed to stop capturing");std::thread::sleep(Duration::from_secs(1));}diff --git a/crates/video-decode/src/ffmpeg.rs b/crates/video-decode/src/ffmpeg.rsindex 200eaf6fd..53d5f9d48 100644--- a/crates/video-decode/src/ffmpeg.rs+++ b/crates/video-decode/src/ffmpeg.rs@@ -380,9 +380,7 @@ impl<'a> Iterator for FramesIter<'a> {Err(e) => return Some(Err(e)),}- let Some((stream, packet)) = self.packets.next() else {- return None;- };+ let (stream, packet) = self.packets.next()?;if stream.index() != self.stream_index {continue;