programmatic video rendering framework that is actually fast
fix: clippy warnings of Rust 1.100
Dmitriy Kovalenko420d9dfa6411
diff --git a/cargo-fframes/src/main.rs b/cargo-fframes/src/main.rsindex 53d0ae99..58afc004 100644--- a/cargo-fframes/src/main.rs+++ b/cargo-fframes/src/main.rs@@ -193,8 +193,7 @@ fn pascal_case(name: &str) -> String {let mut chars = part.chars();chars.next()- .map(|first| first.to_ascii_uppercase().to_string() + chars.as_str())- .unwrap_or_default()+ .map_or_default(|first| first.to_ascii_uppercase().to_string() + chars.as_str())}).collect()}@@ -206,8 +205,7 @@ fn title_case(name: &str) -> String {let mut chars = part.chars();chars.next()- .map(|first| first.to_ascii_uppercase().to_string() + chars.as_str())- .unwrap_or_default()+ .map_or_default(|first| first.to_ascii_uppercase().to_string() + chars.as_str())}).collect::<Vec<_>>().join(" ")@@ -405,20 +403,18 @@ fn new(args: NewArgs) -> Result<(), String> {// Skia renderer and the real-time player (the `preview` command) for GPU backends.let skia_deps = |renderer_source: &str, player_source: &str| {- skia_feature- .map(|f| {- // The workspace dependency turns default features off already.- let player_features = if player_source == "workspace = true" {- format!("features = [\"{f}\", \"audio\"]")- } else {- format!("default-features = false, features = [\"{f}\", \"audio\"]")- };- format!(- "fframes_skia_renderer = {{ {renderer_source}, features = [\"{f}\"] }}\n\+ skia_feature.map_or_default(|f| {+ // The workspace dependency turns default features off already.+ let player_features = if player_source == "workspace = true" {+ format!("features = [\"{f}\", \"audio\"]")+ } else {+ format!("default-features = false, features = [\"{f}\", \"audio\"]")+ };+ format!(+ "fframes_skia_renderer = {{ {renderer_source}, features = [\"{f}\"] }}\n\fframes_native_player = {{ {player_source}, {player_features} }}\n"- )- })- .unwrap_or_default()+ )+ })};let (fframes_dep, skia_dep, dylib_source, media_path, standalone_tables, run) =diff --git a/examples/conference-splash-screen/src/bin/render_all.rs b/examples/conference-splash-screen/src/bin/render_all.rsindex 32806113..e671a954 100644--- a/examples/conference-splash-screen/src/bin/render_all.rs+++ b/examples/conference-splash-screen/src/bin/render_all.rs@@ -19,8 +19,7 @@ fn generate_description(talk: &talks::Talk) -> String {talk.description,talk.social_links.as_deref()- .map(|links| format!("Find speaker: {links}"))- .unwrap_or_default()+ .map_or_default(|links| format!("Find speaker: {links}")))}diff --git a/examples/fframes-intro/src/scenes/agents.rs b/examples/fframes-intro/src/scenes/agents.rsindex ca090ea2..670152ec 100644--- a/examples/fframes-intro/src/scenes/agents.rs+++ b/examples/fframes-intro/src/scenes/agents.rs@@ -223,8 +223,7 @@ fn card(ctx: &FFramesContext, card: &Card, l: f32) -> Svgr<'static> {let ih = iw / aspect;let img = ctx.get_image(name)- .map(|img| fframes::svgr!(<image href={img.href()} x={x + 28.0} y={y + 84.0} width={iw} height={ih} />))- .unwrap_or_default();+ .map_or_default(|img| fframes::svgr!(<image href={img.href()} x={x + 28.0} y={y + 84.0} width={iw} height={ih} />));(fframes::svgr!(<g opacity={body_o}>{img}</g>),84.0 + ih + 28.0,diff --git a/examples/fframes-intro/src/scenes/preview.rs b/examples/fframes-intro/src/scenes/preview.rsindex fe5e0f83..c0e56430 100644--- a/examples/fframes-intro/src/scenes/preview.rs+++ b/examples/fframes-intro/src/scenes/preview.rs@@ -83,7 +83,7 @@ impl Scene for PreviewScene {-(y + h / 2.0));let window = capture- .map(|img| {+ .map_or_default(|img| {fframes::svgr!(<g><clipPath id="preview-win"><rect x={x} y={y} width={w} height={h} rx={radius} /></clipPath>@@ -94,8 +94,7 @@ impl Scene for PreviewScene {<rect x={x} y={y} width={w} height={h} rx={radius} fill="none" stroke="#3d3a35" stroke-width="1.5" opacity={1.0 - full} /></g>)- })- .unwrap_or_default();+ });let keys: Vec<Svgr> = KEYS.iter()diff --git a/examples/fframes-intro/src/scenes/video.rs b/examples/fframes-intro/src/scenes/video.rsindex 6b82be4c..b6d07c66 100644--- a/examples/fframes-intro/src/scenes/video.rs+++ b/examples/fframes-intro/src/scenes/video.rs@@ -99,9 +99,9 @@ impl Scene for VideoScene {let (lx, ly, lw, lh) = LEFT;let (rx, ry, rw, rh) = RIGHT;- let left_img = left- .map(|i| fframes::svgr!(<image href={i.href()} x={lx} y={ly} width={lw} height={lh} />))- .unwrap_or_default();+ let left_img = left.map_or_default(+ |i| fframes::svgr!(<image href={i.href()} x={lx} y={ly} width={lw} height={lh} />),+ );let right_img = if keyed {let flicker = if lb < 4.25 {i32::from(hash(lb * 211.0) > 0.5) as f32@@ -116,7 +116,9 @@ impl Scene for VideoScene {</g>)} else {- right.map(|i| fframes::svgr!(<image href={i.href()} x={rx} y={ry} width={rw} height={rh} />)).unwrap_or_default()+ right.map_or_default(+ |i| fframes::svgr!(<image href={i.href()} x={rx} y={ry} width={rw} height={rh} />),+ )};let exit = expo_in(prog(lb, 5.75, 6.0));diff --git a/examples/podcast/src/podcast.rs b/examples/podcast/src/podcast.rsindex d8940683..aade555e 100644--- a/examples/podcast/src/podcast.rs+++ b/examples/podcast/src/podcast.rs@@ -35,41 +35,32 @@ impl Video for PodcastVideo<'_> {}fn render_frame(&self, frame: Frame, ctx: &FFramesContext) -> Svgr<'_> {- let goose_vis = ctx- .get_audio(self.goose_audio)- .map(|audio| {- frame.visualize_audio_frame(VisualizeFrameInput {- smooth_level: 2,- audio,- sample_size: SampleSize::S32,- window: None,- })+ let goose_vis = ctx.get_audio(self.goose_audio).map_or_default(|audio| {+ frame.visualize_audio_frame(VisualizeFrameInput {+ smooth_level: 2,+ audio,+ sample_size: SampleSize::S32,+ window: None,})- .unwrap_or_default();-- let duck_vis = ctx- .get_audio(self.duck_audio)- .map(|audio| {- frame.visualize_audio_frame(VisualizeFrameInput {- smooth_level: 2,- audio,- sample_size: SampleSize::S32,- window: None,- })+ });++ let duck_vis = ctx.get_audio(self.duck_audio).map_or_default(|audio| {+ frame.visualize_audio_frame(VisualizeFrameInput {+ smooth_level: 2,+ audio,+ sample_size: SampleSize::S32,+ window: None,})- .unwrap_or_default();-- let guest_vis = ctx- .get_audio(self.guest_audio)- .map(|audio| {- frame.visualize_audio_frame(VisualizeFrameInput {- smooth_level: 2,- audio,- sample_size: SampleSize::S32,- window: None,- })+ });++ let guest_vis = ctx.get_audio(self.guest_audio).map_or_default(|audio| {+ frame.visualize_audio_frame(VisualizeFrameInput {+ smooth_level: 2,+ audio,+ sample_size: SampleSize::S32,+ window: None,})- .unwrap_or_default();+ });svgr!(<svg xmlns="http://www.w3.org/2000/svg" width="1920" height="1080">diff --git a/examples/svg-in-3d/tests/recursion.rs b/examples/svg-in-3d/tests/recursion.rsindex ea89972f..e34c8585 100644--- a/examples/svg-in-3d/tests/recursion.rs+++ b/examples/svg-in-3d/tests/recursion.rs@@ -3,7 +3,9 @@//! of the frame land where the projections of the cameras put them, on every backend.#![allow(clippy::unreadable_literal)]-use std::sync::atomic::{AtomicBool, Ordering};+use std::sync::atomic::AtomicBool;+#[cfg(not(target_os = "macos"))]+use std::sync::atomic::Ordering;use fframes::media::ImageData;use fframes::three_d::*;@@ -27,6 +29,7 @@ const C_IN_FRAME: f32 = 64.0;struct Nested {gpu_3d: bool,/// Set when B is a texture on the GPU (`fframes::wgpu_layer`).+ #[cfg_attr(target_os = "macos", allow(dead_code))]b_on_gpu: AtomicBool,}diff --git a/fframes-editor-controller/src/wasm_font_source.rs b/fframes-editor-controller/src/wasm_font_source.rsindex 50fe7727..f6f58e87 100644--- a/fframes-editor-controller/src/wasm_font_source.rs+++ b/fframes-editor-controller/src/wasm_font_source.rs@@ -191,8 +191,10 @@ fn decode_utf16be(data: &[u8]) -> Option<Cow<'_, str>> {// Convert bytes to UTF-16BE code unitslet utf16_units: Vec<u16> = data- .chunks_exact(2)- .map(|chunk| ((chunk[0] as u16) << 8) | (chunk[1] as u16))+ .as_chunks::<2>()+ .0+ .iter()+ .map(|chunk| u16::from_be_bytes(*chunk)).collect();// Decode UTF-16BE to a Rust Stringdiff --git a/fframes-media/src/video_decoder.rs b/fframes-media/src/video_decoder.rsindex 27226d10..f11009b0 100644--- a/fframes-media/src/video_decoder.rs+++ b/fframes-media/src/video_decoder.rs@@ -452,8 +452,7 @@ impl ConvertedFrames {return Vec::new();};Arc::try_unwrap(self.retired.swap_remove(free))- .map(|image| image.data.into_owned())- .unwrap_or_default()+ .map_or_default(|image| image.data.into_owned())}}diff --git a/fframes-skia-renderer/src/backends/vulkan.rs b/fframes-skia-renderer/src/backends/vulkan.rsindex 5c5851bf..52dde51d 100644--- a/fframes-skia-renderer/src/backends/vulkan.rs+++ b/fframes-skia-renderer/src/backends/vulkan.rs@@ -194,8 +194,7 @@ impl SkiaVulkanCtx {#[cfg(feature = "wgpu")]let wgpu_extensions = interop.as_ref()- .map(|interop| interop.extensions().to_vec())- .unwrap_or_default();+ .map_or_default(|interop| interop.extensions().to_vec());#[cfg(not(feature = "wgpu"))]let wgpu_extensions: Vec<&'static std::ffi::CStr> = Vec::new();diff --git a/fframes-skia-renderer/src/backends/vulkan_lifetime_tests.rs b/fframes-skia-renderer/src/backends/vulkan_lifetime_tests.rsindex 2ed1a18c..f47e38ea 100644--- a/fframes-skia-renderer/src/backends/vulkan_lifetime_tests.rs+++ b/fframes-skia-renderer/src/backends/vulkan_lifetime_tests.rs@@ -359,13 +359,16 @@ fn surfaces_release_images_and_memory_on_success_and_failure() {&mut pixels,).unwrap();- for (row, pixels) in pixels.chunks_exact(320 * 4).enumerate() {+ for (row, pixels) in pixels.as_chunks::<{ 320 * 4 }>().0.iter().enumerate() {let expected = if row < 90 {[0, 0, 255, 255]} else {[0, 128, 0, 128]};- assert!(pixels.chunks_exact(4).all(|p| p == expected), "row {row}");+ assert!(+ pixels.as_chunks::<4>().0.iter().all(|p| *p == expected),+ "row {row}"+ );}assert!(IMAGES.load(Ordering::SeqCst) > 0);assert!(MEMORY.load(Ordering::SeqCst) > 0);diff --git a/fframes-skia-renderer/tests/fast_shapes.rs b/fframes-skia-renderer/tests/fast_shapes.rsindex 85ad0a15..5f671ad7 100644--- a/fframes-skia-renderer/tests/fast_shapes.rs+++ b/fframes-skia-renderer/tests/fast_shapes.rs@@ -61,8 +61,10 @@ fn differing_pixels(body: &str) -> usize {let paths = render(&tree(&svg, false));let shapes = render(&tree(&svg, true));paths- .chunks_exact(4)- .zip(shapes.chunks_exact(4))+ .as_chunks::<4>()+ .0+ .iter()+ .zip(shapes.as_chunks::<4>().0).filter(|(a, b)| a.iter().zip(b.iter()).any(|(a, b)| a.abs_diff(*b) > 96)).count()}diff --git a/fframes-three-d/src/gltf.rs b/fframes-three-d/src/gltf.rsindex e9fbc7d7..47340923 100644--- a/fframes-three-d/src/gltf.rs+++ b/fframes-three-d/src/gltf.rs@@ -304,8 +304,7 @@ impl<'g> Loader<'_, 'g> {let reader = skin.reader(|b| buffers.get(b.index()).map(Vec::as_slice));let inverse_bind_matrices = reader.read_inverse_bind_matrices()- .map(|m| m.map(|m| Mat4::from_cols_array_2d(&m)).collect())- .unwrap_or_default();+ .map_or_default(|m| m.map(|m| Mat4::from_cols_array_2d(&m)).collect());let joints = skin.joints().map(|j| self.node_ids.get(&j.index()).copied().unwrap_or(NodeId(0)))@@ -396,8 +395,7 @@ impl<'g> Loader<'_, 'g> {let normals = vec3s(reader.read_normals());let uvs: Vec<Vec2> = reader.read_tex_coords(0)- .map(|uv| uv.into_f32().map(Vec2::from).collect())- .unwrap_or_default();+ .map_or_default(|uv| uv.into_f32().map(Vec2::from).collect());let mut geometry = Geometry::new(positions, normals, uvs, indices);if let Some(colors) = reader.read_colors(0) {geometry.colors = colors.into_rgba_f32().map(Vec4::from).collect();@@ -504,9 +502,7 @@ impl<'g> Loader<'_, 'g> {/// Reads a glTF vector attribute. A missing attribute gives no values.fn vec3s(values: Option<impl Iterator<Item = [f32; 3]>>) -> Vec<Vec3> {- values- .map(|v| v.map(Vec3::from).collect())- .unwrap_or_default()+ values.map_or_default(|v| v.map(Vec3::from).collect())}/// Converts a `KHR_lights_punctual` light. glTF lights shine down -Z of their node.diff --git a/fframes/benches/yuv420_conversion.rs b/fframes/benches/yuv420_conversion.rsindex 9f87062b..f8a60e8a 100644--- a/fframes/benches/yuv420_conversion.rs+++ b/fframes/benches/yuv420_conversion.rs@@ -37,8 +37,8 @@ fn benchmark_yuv420_conversion(c: &mut Criterion) {black_box(y_pixels.as_mut_ptr()),black_box(cb_pixels.as_mut_ptr()),black_box(cr_pixels.as_mut_ptr()),- )- })+ );+ });});#[cfg(target_arch = "aarch64")]@@ -57,9 +57,9 @@ fn benchmark_yuv420_conversion(c: &mut Criterion) {black_box(y_pixels.as_mut_ptr()),black_box(cb_pixels.as_mut_ptr()),black_box(cr_pixels.as_mut_ptr()),- )+ );}- })+ });});}}diff --git a/fframes/src/audio_mix.rs b/fframes/src/audio_mix.rsindex 2300ef9e..d4f39496 100644--- a/fframes/src/audio_mix.rs+++ b/fframes/src/audio_mix.rs@@ -421,9 +421,7 @@ impl<'m> AudioMixer<'m> {options: AudioMixOptions,) -> Self {let mut missing = Vec::new();- let resolved = audio_map- .map(super::audio_map::ResolvedAudioMap::tracks)- .unwrap_or_default();+ let resolved = audio_map.map_or_default(super::audio_map::ResolvedAudioMap::tracks);let rate = sample_rate as f64;let rescale = sample_rate as f64 / map_sample_rate.max(1) as f64;let to_output = |sample: usize| (sample as f64 * rescale).round() as usize;diff --git a/fframes/src/diagnostics.rs b/fframes/src/diagnostics.rsindex 04575251..89d3dfbc 100644--- a/fframes/src/diagnostics.rs+++ b/fframes/src/diagnostics.rs@@ -162,8 +162,7 @@ pub(crate) fn report_missing_media(media: MediaKind, name: &str) {pub fn take_missing_media() -> Vec<(MediaKind, String)> {MISSING_MEDIA.lock()- .map(|mut missing| std::mem::take(&mut *missing).into_iter().collect())- .unwrap_or_default()+ .map_or_default(|mut missing| std::mem::take(&mut *missing).into_iter().collect())}fn dedup(diagnostics: Vec<Diagnostic>) -> Vec<Diagnostic> {diff --git a/fframes/src/lottie.rs b/fframes/src/lottie.rsindex 7591623a..efe10355 100644--- a/fframes/src/lottie.rs+++ b/fframes/src/lottie.rs@@ -225,11 +225,7 @@ impl SvgrSink {while self.stack.len() > 1 {self.pop_layer();}- let children = self- .stack- .pop()- .map(|(_, children)| children)- .unwrap_or_default();+ let children = self.stack.pop().map_or_default(|(_, children)| children);svgr!(<g>{children}</g>)}diff --git a/fframes/src/renderer/fframes_logger.rs b/fframes/src/renderer/fframes_logger.rsindex 0a702277..ed2d266e 100644--- a/fframes/src/renderer/fframes_logger.rs+++ b/fframes/src/renderer/fframes_logger.rs@@ -76,9 +76,7 @@ impl FFramesLogger for CompactFFramesLogger {"Success!".green().bold(),"ffplay".bold(),output_path.display(),- temp_files_dir- .map(|path| format!("Generated files {}\n", path.display()))- .unwrap_or_default()+ temp_files_dir.map_or_default(|path| format!("Generated files {}\n", path.display())));}diff --git a/fframes/src/renderer/preview.rs b/fframes/src/renderer/preview.rsindex c5a91f75..ca5ae72d 100644--- a/fframes/src/renderer/preview.rs+++ b/fframes/src/renderer/preview.rs@@ -394,7 +394,7 @@ impl<'a, 'media: 'a, TVideo: Video> Previewer<'a, 'media, TVideo> {.timeline.audio_map.as_ref()- .map(|map| {+ .map_or_default(|map| {use crate::AudioTimelineUnit;map.tracks().iter()@@ -405,8 +405,7 @@ impl<'a, 'media: 'a, TVideo: Video> Previewer<'a, 'media, TVideo> {mix: track.mix.clone(),}).collect()- })- .unwrap_or_default(),+ }),}}diff --git a/fframes/src/time_spec.rs b/fframes/src/time_spec.rsindex fbff8787..19d6d6ad 100644--- a/fframes/src/time_spec.rs+++ b/fframes/src/time_spec.rs@@ -102,20 +102,18 @@ impl TimelineIndex {Self {fps,duration_in_frames,- scenes: scenes- .map(|scenes| {- scenes- .timeline- .iter()- .map(|(range, info, scene)| TimelineScene {- index: info.index,- name: short_scene_name(scene.name()).to_owned(),- full_name: scene.name().to_owned(),- frames: range.clone(),- })- .collect()- })- .unwrap_or_default(),+ scenes: scenes.map_or_default(|scenes| {+ scenes+ .timeline+ .iter()+ .map(|(range, info, scene)| TimelineScene {+ index: info.index,+ name: short_scene_name(scene.name()).to_owned(),+ full_name: scene.name().to_owned(),+ frames: range.clone(),+ })+ .collect()+ }),}}diff --git a/fframes/src/video_data.rs b/fframes/src/video_data.rsindex 721135ed..92f19d8f 100644--- a/fframes/src/video_data.rs+++ b/fframes/src/video_data.rs@@ -296,14 +296,12 @@ impl DecoderPool {let (_, decoders) = matches.next()?;matches.next().is_none().then_some(decoders)});- decoders- .map(|decoders| {- decoders- .iter()- .map(|(_, entry)| Arc::clone(&entry.slot))- .collect()- })- .unwrap_or_default()+ decoders.map_or_default(|decoders| {+ decoders+ .iter()+ .map(|(_, entry)| Arc::clone(&entry.slot))+ .collect()+ })}fn finish_frame(&mut self, concurrent_jobs: usize) -> Vec<DecoderSlot> {