diff --git a/apps/deckcraft-cli/src/main.rs b/apps/deckcraft-cli/src/main.rs index c6276efb..a3c03ce2 100644 --- a/apps/deckcraft-cli/src/main.rs +++ b/apps/deckcraft-cli/src/main.rs @@ -407,7 +407,7 @@ fn frame_paths(out: &str, ts: &[f64]) -> Result, String> { return Ok(vec![out.to_string()]); } let p = std::path::Path::new(out); - let stem = p.file_stem().and_then(|x| x.to_str()).unwrap_or("frame"); + let stem = p.file_stem().and_then(std::ffi::OsStr::to_str).unwrap_or("frame"); let mut paths: Vec = Vec::with_capacity(ts.len()); for t in ts { let path = p.with_file_name(format!("{stem}-t{t:.3}.png")).to_string_lossy().into_owned(); diff --git a/crates/av1/src/cdef.rs b/crates/av1/src/cdef.rs index abae4bc0..9860f65c 100644 --- a/crates/av1/src/cdef.rs +++ b/crates/av1/src/cdef.rs @@ -242,14 +242,14 @@ fn filter_rows( } for i in 0..h { let ci = ((i + 2) * PAD_STRIDE + 2) as isize; - let Some(&x) = b16.get(ci as usize..).and_then(|r| r.first_chunk::()) else { + let Some(&x) = b16.get(ci as usize..).and_then(<[_]>::first_chunk::) else { return; }; let (mut sum, mut max, mut min) = ([0i16; W], x, x); for &(off, weight, thr, adj) in taps { let (weight, thr) = (weight as i16, thr as i16); let start = (ci + off) as usize; - let Some(p) = b16.get(start..).and_then(|r| r.first_chunk::()) else { + let Some(p) = b16.get(start..).and_then(<[_]>::first_chunk::) else { return; }; for j in 0..W { diff --git a/crates/av1/src/decoder.rs b/crates/av1/src/decoder.rs index 06de1589..3e0aa237 100644 --- a/crates/av1/src/decoder.rs +++ b/crates/av1/src/decoder.rs @@ -61,7 +61,7 @@ impl Slot { } fn set(&self, v: Result) { - let mut g = self.value.lock().unwrap_or_else(|e| e.into_inner()); + let mut g = self.value.lock().unwrap_or_else(std::sync::PoisonError::into_inner); *g = Some(v); self.cv.notify_all(); } @@ -71,12 +71,12 @@ impl Slot { } fn wait(&self) -> Result { - let mut g = self.value.lock().unwrap_or_else(|e| e.into_inner()); + let mut g = self.value.lock().unwrap_or_else(std::sync::PoisonError::into_inner); loop { if let Some(v) = g.as_ref() { return v.clone(); } - g = self.cv.wait(g).unwrap_or_else(|e| e.into_inner()); + g = self.cv.wait(g).unwrap_or_else(std::sync::PoisonError::into_inner); } } } diff --git a/crates/av1/src/frame.rs b/crates/av1/src/frame.rs index 3cf4b9f0..f3243551 100644 --- a/crates/av1/src/frame.rs +++ b/crates/av1/src/frame.rs @@ -16,7 +16,7 @@ const POOL_MAX_SAMPLES: usize = 96 << 20; fn zeroed(len: usize) -> Vec { if len >= POOL_MIN_LEN { let found = { - let mut pool = PLANE_POOL.lock().unwrap_or_else(|e| e.into_inner()); + let mut pool = PLANE_POOL.lock().unwrap_or_else(std::sync::PoisonError::into_inner); pool.iter().position(|v| v.capacity() >= len && v.capacity() <= 2 * len).map(|i| pool.swap_remove(i)) }; if let Some(mut v) = found { @@ -52,8 +52,8 @@ impl Drop for Plane { fn drop(&mut self) { if self.data.capacity() >= POOL_MIN_LEN { let v = std::mem::take(&mut self.data); - let mut pool = PLANE_POOL.lock().unwrap_or_else(|e| e.into_inner()); - let kept: usize = pool.iter().map(|b| b.capacity()).sum(); + let mut pool = PLANE_POOL.lock().unwrap_or_else(std::sync::PoisonError::into_inner); + let kept: usize = pool.iter().map(Vec::capacity).sum(); if kept + v.capacity() <= POOL_MAX_SAMPLES { pool.push(v); } diff --git a/crates/av1/src/inter.rs b/crates/av1/src/inter.rs index 76c0ef1a..d3418a99 100644 --- a/crates/av1/src/inter.rs +++ b/crates/av1/src/inter.rs @@ -678,7 +678,7 @@ fn hpass(src: &[u16], hf: &[i16; 8], out: &mut [i32], half: i32, let mut acc = [half; W]; for t in 0..8 { let f = hf[t] as i32; - let Some(p) = src.get(t..).and_then(|s| s.first_chunk::()) else { + let Some(p) = src.get(t..).and_then(<[_]>::first_chunk::) else { return; }; for j in 0..W { @@ -699,7 +699,7 @@ fn vpass(rows: &[i32], vf: &[i16; 8], out: &mut [i32], half: i32 let mut acc = [half; W]; for t in 0..8 { let f = vf[t] as i32; - let Some(p) = rows.get(t * W..).and_then(|s| s.first_chunk::()) else { + let Some(p) = rows.get(t * W..).and_then(<[_]>::first_chunk::) else { return; }; for j in 0..W { diff --git a/crates/engine/src/cmd/insert.rs b/crates/engine/src/cmd/insert.rs index 4f28ddef..8bc45380 100644 --- a/crates/engine/src/cmd/insert.rs +++ b/crates/engine/src/cmd/insert.rs @@ -577,7 +577,7 @@ fn commit_album(s: &mut Session, items: Vec, opts: AlbumOpts, replace } fn album_norm(s: &str) -> String { - s.chars().filter(|c| c.is_ascii_alphanumeric()).collect::().to_ascii_lowercase() + s.chars().filter(char::is_ascii_alphanumeric).collect::().to_ascii_lowercase() } fn album_layout(p: &Value) -> Result { @@ -770,7 +770,7 @@ fn image_px(bytes: &[u8]) -> (f64, f64) { } fn file_stem(name: &str) -> String { - let base = std::path::Path::new(name).file_name().and_then(|n| n.to_str()).unwrap_or(name); + let base = std::path::Path::new(name).file_name().and_then(std::ffi::OsStr::to_str).unwrap_or(name); let stem = match base.rsplit_once('.') { Some((s, ext)) if !s.is_empty() && !ext.is_empty() => s, _ => base, diff --git a/crates/h264/src/deblock.rs b/crates/h264/src/deblock.rs index ded8396c..0d815aff 100644 --- a/crates/h264/src/deblock.rs +++ b/crates/h264/src/deblock.rs @@ -232,7 +232,7 @@ fn filter_vertical(pix: &mut [u8], stride: usize, x: usize, y: u let mut w = [0u64; N]; for (i, w) in w.iter_mut().enumerate() { let o = (y + i) * stride + x - 4; - let Some(&b) = pix.get(o..).and_then(|p| p.first_chunk::<8>()) else { + let Some(&b) = pix.get(o..).and_then(<[_]>::first_chunk::<8>) else { return; }; *w = u64::from_le_bytes(b); @@ -259,7 +259,7 @@ fn filter_horizontal(pix: &mut [u8], stride: usize, x: usize, y: let base = (y - 4) * stride + x; let mut s = [[0i16; N]; 8]; for (k, row) in s.iter_mut().enumerate() { - let Some(src) = pix.get(base + k * stride..).and_then(|p| p.first_chunk::()) else { + let Some(src) = pix.get(base + k * stride..).and_then(<[_]>::first_chunk::) else { return; }; for i in 0..N { @@ -269,7 +269,7 @@ fn filter_horizontal(pix: &mut [u8], stride: usize, x: usize, y: filter_lanes(&mut s, ep, chroma); let (k0, k1) = if chroma { (3, 5) } else { (1, 7) }; for (k, row) in s.iter().enumerate().take(k1).skip(k0) { - let Some(dst) = pix.get_mut(base + k * stride..).and_then(|p| p.first_chunk_mut::()) else { + let Some(dst) = pix.get_mut(base + k * stride..).and_then(<[_]>::first_chunk_mut::) else { return; }; for i in 0..N { diff --git a/crates/h264/src/picture.rs b/crates/h264/src/picture.rs index 8a9f0a94..d97fa063 100644 --- a/crates/h264/src/picture.rs +++ b/crates/h264/src/picture.rs @@ -301,7 +301,7 @@ fn plane_allocator() -> fn(usize) -> Vec { fn copy_line(line: &[u8], x0: i32, out: &mut [u8], w: usize) { if w <= N && x0 >= 0 - && let Some(src) = line.get(x0 as usize..).and_then(|l| l.first_chunk::()) + && let Some(src) = line.get(x0 as usize..).and_then(<[_]>::first_chunk::) && let Some(dst) = out.first_chunk_mut::() { *dst = *src; diff --git a/crates/h264/src/slicedec.rs b/crates/h264/src/slicedec.rs index 10132d68..d1334808 100644 --- a/crates/h264/src/slicedec.rs +++ b/crates/h264/src/slicedec.rs @@ -907,7 +907,7 @@ impl<'a> SliceDecoder<'a> { let stride = self.pic.planes.width; let px = self.mb_x * 16 + (raster & 3) * 4; let py = self.mb_y * 16 + (raster >> 2) * 4; - let Some(blk) = self.s.coef.get_mut(raster * 16..).and_then(|c| c.first_chunk_mut::<16>()) else { + let Some(blk) = self.s.coef.get_mut(raster * 16..).and_then(<[_]>::first_chunk_mut::<16>) else { return; }; transform::idct4_add(blk, &mut self.pic.planes.y[py * stride + px..], stride); @@ -921,7 +921,7 @@ impl<'a> SliceDecoder<'a> { let stride = self.pic.planes.width; let px = self.mb_x * 16 + (b8 & 1) * 8; let py = self.mb_y * 16 + (b8 >> 1) * 8; - let Some(blk) = self.s.coef.get_mut(b8 * 64..).and_then(|c| c.first_chunk_mut::<64>()) else { + let Some(blk) = self.s.coef.get_mut(b8 * 64..).and_then(<[_]>::first_chunk_mut::<64>) else { return; }; transform::idct8_add(blk, &mut self.pic.planes.y[py * stride + px..], stride); @@ -940,7 +940,7 @@ impl<'a> SliceDecoder<'a> { } let px = self.mb_x * 8 + (b & 1) * 4; let py = self.mb_y * 8 + (b >> 1) * 4; - let Some(blk) = self.s.coef_c[c].get_mut(b * 16..).and_then(|c| c.first_chunk_mut::<16>()) else { + let Some(blk) = self.s.coef_c[c].get_mut(b * 16..).and_then(<[_]>::first_chunk_mut::<16>) else { continue; }; let plane = if c == 0 { &mut self.pic.planes.cb } else { &mut self.pic.planes.cr }; diff --git a/crates/h264/src/synth_tests.rs b/crates/h264/src/synth_tests.rs index ec5f601d..a0c9da2f 100644 --- a/crates/h264/src/synth_tests.rs +++ b/crates/h264/src/synth_tests.rs @@ -107,7 +107,7 @@ struct Pic { impl Pic { fn is_p(&self) -> bool { - !self.idr && !self.b && self.mbs.iter().any(|m| m.is_none()) + !self.idr && !self.b && self.mbs.iter().any(Option::is_none) } fn inter(&self) -> bool { self.b || self.is_p() diff --git a/crates/h264/src/transform.rs b/crates/h264/src/transform.rs index f87a1c98..131ea98c 100644 --- a/crates/h264/src/transform.rs +++ b/crates/h264/src/transform.rs @@ -117,7 +117,7 @@ pub fn idct4_add(d: &[i32; 16], dst: &mut [u8], stride: usize) { o[3][j] = e - h; } for (i, row) in o.iter().enumerate() { - let Some(line) = dst.get_mut(i * stride..).and_then(|d| d.first_chunk_mut::<4>()) else { + let Some(line) = dst.get_mut(i * stride..).and_then(<[_]>::first_chunk_mut::<4>) else { return; }; for (p, &v) in line.iter_mut().zip(row) { @@ -173,7 +173,7 @@ pub fn idct8_add(d: &[i32; 64], dst: &mut [u8], stride: usize) { } } for (i, row) in o.iter().enumerate() { - let Some(line) = dst.get_mut(i * stride..).and_then(|d| d.first_chunk_mut::<8>()) else { + let Some(line) = dst.get_mut(i * stride..).and_then(<[_]>::first_chunk_mut::<8>) else { return; }; for (p, &v) in line.iter_mut().zip(row) { diff --git a/crates/hevc/src/inter.rs b/crates/hevc/src/inter.rs index de0f28e7..8d1b6751 100644 --- a/crates/hevc/src/inter.rs +++ b/crates/hevc/src/inter.rs @@ -25,7 +25,7 @@ fn filt_w(src: &[i16], step: usize, f: &[i8; T], let mut acc = [0i32; W]; for k in 0..T { let c = f[k] as i32; - let Some(p) = src.get(k * step..).and_then(|s| s.first_chunk::()) else { + let Some(p) = src.get(k * step..).and_then(<[_]>::first_chunk::) else { return; }; for j in 0..W { diff --git a/crates/metafile/src/tests.rs b/crates/metafile/src/tests.rs index 09e76413..b54f4ec2 100644 --- a/crates/metafile/src/tests.rs +++ b/crates/metafile/src/tests.rs @@ -1217,7 +1217,7 @@ fn savedc_restores_text_colour_and_font() { fn efont(height: i32, esc: i32, weight: i32, italic: u8, charset: u8, face: &str) -> Vec { let mut v = cat(vec![h32(1), e32(height), e32(0), e32(esc), e32(esc), e32(weight)]); v.extend([italic, 0, 0, charset, 0, 0, 0, 0]); - let mut name: Vec = face.encode_utf16().flat_map(|u| u.to_le_bytes()).collect(); + let mut name: Vec = face.encode_utf16().flat_map(u16::to_le_bytes).collect(); name.resize(64, 0); v.extend(name); erec(82, &v) diff --git a/crates/pptx/tests/it/corpus_kinds.rs b/crates/pptx/tests/it/corpus_kinds.rs index 56fc5adf..b229f3ff 100644 --- a/crates/pptx/tests/it/corpus_kinds.rs +++ b/crates/pptx/tests/it/corpus_kinds.rs @@ -437,7 +437,7 @@ fn next_rid(rels: &str) -> String { let mut max = 0u32; let mut rest = rels; while let Some(i) = rest.find("rId") { - let digits: String = rest[i + 3..].chars().take_while(|c| c.is_ascii_digit()).collect(); + let digits: String = rest[i + 3..].chars().take_while(char::is_ascii_digit).collect(); if let Ok(n) = digits.parse::() { max = max.max(n); } diff --git a/crates/render/src/morph_text.rs b/crates/render/src/morph_text.rs index 74cd4b7f..391ec0ba 100644 --- a/crates/render/src/morph_text.rs +++ b/crates/render/src/morph_text.rs @@ -208,7 +208,7 @@ pub(crate) fn draw( } } let unmatched_b = - tb.iter().enumerate().filter(|(j, _)| pairs.get(*j).is_none_or(|p| p.is_none())).flat_map(|(_, tok)| tok.glyphs.iter().copied()); + tb.iter().enumerate().filter(|(j, _)| pairs.get(*j).is_none_or(Option::is_none)).flat_map(|(_, tok)| tok.glyphs.iter().copied()); for g in unmatched_b.chain(loose_b) { if let Some((run, gid, pos)) = glyph_at(&lb, g) { draw_glyph(ctx, run, gid, place_b * Affine::translate(pos.to_vec2()), t); diff --git a/crates/ui-egui/src/backstage.rs b/crates/ui-egui/src/backstage.rs index 999900d3..774bb974 100644 --- a/crates/ui-egui/src/backstage.rs +++ b/crates/ui-egui/src/backstage.rs @@ -572,8 +572,8 @@ fn template_tiles(app: &mut SlideApp, ui: &mut Ui, query: &str, limit: usize) -> /// File name and folder of a recent path, split as text (nothing on disk is read). pub fn split_path(path: &str) -> (String, String) { let p = std::path::Path::new(path); - let name = p.file_name().and_then(|n| n.to_str()).unwrap_or(path).to_string(); - let folder = p.parent().and_then(|f| f.to_str()).unwrap_or("").to_string(); + let name = p.file_name().and_then(std::ffi::OsStr::to_str).unwrap_or(path).to_string(); + let folder = p.parent().and_then(std::path::Path::to_str).unwrap_or("").to_string(); (name, folder) } @@ -827,7 +827,7 @@ fn info(app: &mut SlideApp, ui: &mut Ui, bs: &mut Backstage) { app.set_status("Copied the path"); } #[cfg(not(target_arch = "wasm32"))] - if let Some(dir) = std::path::Path::new(p).parent().and_then(|d| d.to_str()) + if let Some(dir) = std::path::Path::new(p).parent().and_then(std::path::Path::to_str) && ui.button("Open file location").clicked() { app.open_url(&format!("file:///{}", dir.replace('\\', "/").trim_start_matches('/'))); diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index efe8a07f..1193efeb 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -272,7 +272,7 @@ fn pick_album_picture(app: &mut SlideApp) -> Option { app.set_status("That picture is larger than 32 MB"); return None; } - let name = std::path::Path::new(&path).file_name().and_then(|n| n.to_str()).filter(|s| !s.is_empty()).unwrap_or("picture").to_string(); + let name = std::path::Path::new(&path).file_name().and_then(std::ffi::OsStr::to_str).filter(|s| !s.is_empty()).unwrap_or("picture").to_string(); Some(json!({"name": name, "data": deckcraft_engine::cmd::base64_encode(&loaded)})) } diff --git a/crates/vp9/src/boolcoder.rs b/crates/vp9/src/boolcoder.rs index de56d5c1..73e0e1c5 100644 --- a/crates/vp9/src/boolcoder.rs +++ b/crates/vp9/src/boolcoder.rs @@ -29,7 +29,7 @@ impl<'a> BoolDecoder<'a> { fn fill(&mut self) { // Room for whole bytes below the top 8 bits and the `count` valid bits. let mut shift = 48 - self.count; - if let Some(&bytes) = self.data.get(self.pos..).and_then(|d| d.first_chunk::<8>()) { + if let Some(&bytes) = self.data.get(self.pos..).and_then(<[_]>::first_chunk::<8>) { let v = u64::from_be_bytes(bytes); let n = ((shift + 8) / 8) as usize; // bytes that fit let n = n.min(7); diff --git a/crates/vp9/src/decoder.rs b/crates/vp9/src/decoder.rs index 28e9d6d2..ce05d4b1 100644 --- a/crates/vp9/src/decoder.rs +++ b/crates/vp9/src/decoder.rs @@ -347,7 +347,7 @@ impl Decoder { let sz = if last { data.len() - pos } else { - let Some(&b) = data.get(pos..).and_then(|d| d.first_chunk::<4>()) else { + let Some(&b) = data.get(pos..).and_then(<[_]>::first_chunk::<4>) else { return Err(Error::Invalid("tile size beyond frame data".into())); }; let s = u32::from_be_bytes(b) as usize; diff --git a/crates/vp9/src/inter.rs b/crates/vp9/src/inter.rs index 14f2ee22..32188181 100644 --- a/crates/vp9/src/inter.rs +++ b/crates/vp9/src/inter.rs @@ -148,7 +148,7 @@ fn filter_h_n(s: &[u16], f: &[i16], max: i32, o: &mut [u16]) { let mut acc = [64u16; W]; for t in 0..8 { let c = f[t] as u16; - let Some(p) = s.get(t..).and_then(|s| s.first_chunk::()) else { + let Some(p) = s.get(t..).and_then(<[_]>::first_chunk::) else { return; }; for j in 0..W { @@ -161,7 +161,7 @@ fn filter_h_n(s: &[u16], f: &[i16], max: i32, o: &mut [u16]) { let mut acc = [64i32; W]; for t in 0..8 { let c = f[t] as i32; - let Some(p) = s.get(t..).and_then(|s| s.first_chunk::()) else { + let Some(p) = s.get(t..).and_then(<[_]>::first_chunk::) else { return; }; for j in 0..W { @@ -212,7 +212,7 @@ fn filter_v_n(s: &[u16], ss: usize, f: &[i16], max: i32, o: &mut let mut acc = [64u16; W]; for t in 0..8 { let c = f[t] as u16; - let Some(p) = s.get(t * ss..).and_then(|s| s.first_chunk::()) else { + let Some(p) = s.get(t * ss..).and_then(<[_]>::first_chunk::) else { return; }; for j in 0..W { @@ -225,7 +225,7 @@ fn filter_v_n(s: &[u16], ss: usize, f: &[i16], max: i32, o: &mut let mut acc = [64i32; W]; for t in 0..8 { let c = f[t] as i32; - let Some(p) = s.get(t * ss..).and_then(|s| s.first_chunk::()) else { + let Some(p) = s.get(t * ss..).and_then(<[_]>::first_chunk::) else { return; }; for j in 0..W { diff --git a/crates/vp9/src/transform.rs b/crates/vp9/src/transform.rs index 30658a9c..4e02ba11 100644 --- a/crates/vp9/src/transform.rs +++ b/crates/vp9/src/transform.rs @@ -161,7 +161,7 @@ pub fn inverse_transform_add( if lossless { let mut t = [0i32; 16]; for i in 0..4 { - let c = coefs.get(i * 4..).and_then(|c| c.first_chunk::<4>()).copied().unwrap_or_default(); + let c = coefs.get(i * 4..).and_then(<[_]>::first_chunk::<4>).copied().unwrap_or_default(); let r = iwht4(c, 2); t[i * 4..i * 4 + 4].copy_from_slice(&r); } @@ -235,7 +235,7 @@ fn itx_narrow(coefs: &[i32], p: &TxParams, dst: &mut [u16], stri add_cols(&y, 0, p, dst, stride); } else { for c0 in (0..N).step_by(8) { - let x: [Cols<8>; N] = std::array::from_fn(|i| Cols(t[i].get(c0..).and_then(|r| r.first_chunk::<8>()).copied().unwrap_or_default())); + let x: [Cols<8>; N] = std::array::from_fn(|i| Cols(t[i].get(c0..).and_then(<[_]>::first_chunk::<8>).copied().unwrap_or_default())); let y = col_tx8(x, p.col_adst); add_cols(&y, c0, p, dst, stride); } @@ -246,7 +246,7 @@ fn itx_narrow(coefs: &[i32], p: &TxParams, dst: &mut [u16], stri #[inline(always)] fn add_cols(y: &[Cols; N], c0: usize, p: &TxParams, dst: &mut [u16], stride: usize) { for (i, v) in y.iter().enumerate() { - let Some(d) = dst.get_mut(i * stride + c0..).and_then(|d| d.first_chunk_mut::()) else { + let Some(d) = dst.get_mut(i * stride + c0..).and_then(<[_]>::first_chunk_mut::) else { return; }; for j in 0..W {