Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Lint: as_chunks for constant chunk sizes, as clippy 1.99 asks

theironchef945dcbae1d44
diff --git a/crates/eps/src/import/graphics.rs b/crates/eps/src/import/graphics.rs
index 823e2ed9d..005a433db 100644
--- a/crates/eps/src/import/graphics.rs
+++ b/crates/eps/src/import/graphics.rs
@@ -429,10 +429,8 @@ impl Interp<'_> {
return Err(PsError::Limit("a path has too many points"));
}
let mut bp = BezPath::new();
- for r in nums.chunks_exact(4) {
- if let [x, y, w, h] = r {
- bp.extend(self.rect_path(*x, *y, *w, *h));
- }
+ for [x, y, w, h] in nums.as_chunks::<4>().0 {
+ bp.extend(self.rect_path(*x, *y, *w, *h));
}
Ok(bp)
}
diff --git a/crates/metafile/src/dib.rs b/crates/metafile/src/dib.rs
index d63e5837a..ef98ef155 100644
--- a/crates/metafile/src/dib.rs
+++ b/crates/metafile/src/dib.rs
@@ -92,7 +92,7 @@ pub(crate) fn rgb24(img: &Rgba, opacity: f32) -> (Vec<u8>, Vec<u8>) {
// Bottom-up: the first stored row is the image's last.
let Some(at) = (img.height as usize).checked_sub(y + 1).map(|r| r * row) else { continue };
let Some(dst) = bits.get_mut(at..at + img.width as usize * 3) else { continue };
- for (d, p) in dst.chunks_exact_mut(3).zip(src.as_chunks::<4>().0) {
+ for (d, p) in dst.as_chunks_mut::<3>().0.iter_mut().zip(src.as_chunks::<4>().0) {
let a = (f32::from(p[3]) * opacity.clamp(0.0, 1.0)).round() as u32;
d.copy_from_slice(&[over(p[2], a), over(p[1], a), over(p[0], a)]);
}
@@ -107,7 +107,7 @@ pub(crate) fn bgra32(img: &Rgba, opacity: f32) -> (Vec<u8>, Vec<u8>) {
for (y, src) in img.pixels.chunks_exact(row.max(1)).enumerate() {
let Some(at) = (img.height as usize).checked_sub(y + 1).map(|r| r * row) else { continue };
let Some(dst) = bits.get_mut(at..at + row) else { continue };
- for (d, p) in dst.chunks_exact_mut(4).zip(src.as_chunks::<4>().0) {
+ for (d, p) in dst.as_chunks_mut::<4>().0.iter_mut().zip(src.as_chunks::<4>().0) {
let a = (f32::from(p[3]) * opacity.clamp(0.0, 1.0)).round() as u32;
let pre = |c: u8| ((u32::from(c) * a + 127) / 255) as u8;
d.copy_from_slice(&[pre(p[2]), pre(p[1]), pre(p[0]), a as u8]);
diff --git a/crates/metafile/src/import.rs b/crates/metafile/src/import.rs
index 482f2293f..ecc6a7f1d 100644
--- a/crates/metafile/src/import.rs
+++ b/crates/metafile/src/import.rs
@@ -583,7 +583,7 @@ impl Player {
let mut bp = BezPath::new();
bp.move_to(*first);
if bezier {
- for c in rest.chunks_exact(3) {
+ for c in rest.as_chunks::<3>().0 {
bp.curve_to(c[0], c[1], c[2]);
}
} else {
@@ -636,7 +636,7 @@ impl Player {
}
};
if bezier {
- for c in pts.chunks_exact(3) {
+ for c in pts.as_chunks::<3>().0 {
target.curve_to(xf * c[0], xf * c[1], xf * c[2]);
}
} else {
diff --git a/crates/metafile/src/import/emf.rs b/crates/metafile/src/import/emf.rs
index e0eedd01f..e2024af22 100644
--- a/crates/metafile/src/import/emf.rs
+++ b/crates/metafile/src/import/emf.rs
@@ -314,7 +314,7 @@ fn record(p: &mut Player, kind: u32, rec: &[u8]) -> Option<()> {
let off = r.u32()?;
let s = if kind == 84 {
let raw = slice(rec, off, u32::try_from(n.checked_mul(2)?).ok()?)?;
- String::from_utf16_lossy(&raw.chunks_exact(2).map(|c| u16::from_le_bytes([c[0], c[1]])).collect::<Vec<_>>())
+ String::from_utf16_lossy(&raw.as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes(*c)).collect::<Vec<_>>())
} else {
slice(rec, off, u32::try_from(n).ok()?)?.iter().map(|b| char::from(*b)).collect()
};
diff --git a/crates/metafile/src/wmf.rs b/crates/metafile/src/wmf.rs
index 5ef36bf0f..0e4b82e08 100644
--- a/crates/metafile/src/wmf.rs
+++ b/crates/metafile/src/wmf.rs
@@ -68,7 +68,7 @@ pub(crate) fn units_per_inch(w: f64, h: f64) -> u16 {
/// The XOR of the first ten 16-bit words of a placeable header.
pub(crate) fn checksum(header: &[u8]) -> u16 {
- header.chunks_exact(2).take(10).fold(0, |acc, w| acc ^ u16::from_le_bytes([w[0], w[1]]))
+ header.as_chunks::<2>().0.iter().take(10).fold(0, |acc, w| acc ^ u16::from_le_bytes(*w))
}
/// `bp` flattened to within `tol`: each subpath's points and whether it closes.
diff --git a/crates/pdf/src/encrypt.rs b/crates/pdf/src/encrypt.rs
index 173f1de57..39a9ff48b 100644
--- a/crates/pdf/src/encrypt.rs
+++ b/crates/pdf/src/encrypt.rs
@@ -232,12 +232,11 @@ impl Aes {
prev = self.block(std::array::from_fn(|i| chunk[i] ^ prev[i]));
out.extend_from_slice(&prev);
};
- let mut chunks = data.chunks_exact(16);
- for c in &mut chunks {
- put(std::array::from_fn(|i| c.get(i).copied().unwrap_or_default()), &mut out);
+ let (chunks, rest) = data.as_chunks::<16>();
+ for c in chunks {
+ put(*c, &mut out);
}
if pad {
- let rest = chunks.remainder();
let n = (16 - rest.len()) as u8;
put(std::array::from_fn(|i| rest.get(i).copied().unwrap_or(n)), &mut out);
}