DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
CI: fix new Rust 1.99 clippy lints (as_chunks, ?, redundant ref)
Brandon Thomas8490965e7144
diff --git a/crates/engine/src/cmd/xml.rs b/crates/engine/src/cmd/xml.rsindex c26d4ef4e..3c73f30fa 100644--- a/crates/engine/src/cmd/xml.rs+++ b/crates/engine/src/cmd/xml.rs@@ -531,7 +531,9 @@ mod tests {let count = |opts: &designcraft_render::RenderOptions, rr: &mut designcraft_render::Renderer| {let img = rr.render_page(&d, &s.cache, 0, 2.0, false, opts).unwrap();img.pixels- .chunks_exact(4)+ .as_chunks::<4>()+ .0+ .iter().filter(|p| {(p[0] as i32 - col[0] as i32).abs() < 30 && (p[1] as i32 - col[1] as i32).abs() < 30 && (p[2] as i32 - col[2] as i32).abs() < 30})diff --git a/crates/idml/src/import.rs b/crates/idml/src/import.rsindex d0ecf2477..a3a97b910 100644--- a/crates/idml/src/import.rs+++ b/crates/idml/src/import.rs@@ -535,7 +535,7 @@ impl<'r> Importer<'r> {let nums = |k: &str| e.get(k).unwrap_or("").split_whitespace().filter_map(|x| x.parse::<f64>().ok()).collect::<Vec<_>>();let kind = match e.local() {"StripedStrokeStyle" => designcraft_doc::StrokeType::Stripes {- bands: nums("StripeArray").chunks_exact(2).map(|c| (c[0] / 100.0, (c[1] - c[0]) / 100.0)).collect(),+ bands: nums("StripeArray").as_chunks::<2>().0.iter().map(|c| (c[0] / 100.0, (c[1] - c[0]) / 100.0)).collect(),},"DashedStrokeStyle" => designcraft_doc::StrokeType::Dashed { pattern: nums("DashArray") },_ => designcraft_doc::StrokeType::Dotted,diff --git a/crates/pdf/src/pdfx.rs b/crates/pdf/src/pdfx.rsindex 2419fcaf0..891cf2e47 100644--- a/crates/pdf/src/pdfx.rs+++ b/crates/pdf/src/pdfx.rs@@ -92,14 +92,12 @@ pub fn make_pdfx4(pdf: &[u8], title: &str) -> Option<Vec<u8>> {}let add = "<rdf:Description rdf:about=\"\" xmlns:pdfxid=\"http://www.npes.org/pdfx/ns/id/\"><pdfxid:GTS_PDFXVersion>PDF/X-4</pdfxid:GTS_PDFXVersion></rdf:Description>";let xml = xml.replacen("</rdf:RDF>", &format!("{add}</rdf:RDF>"), 1);- let dict = match dict.find("/Length") {- Some(i) => {- let rest = &dict[i + 7..];- let rest = rest.trim_start();- let end = rest.find(|c: char| !c.is_ascii_digit()).unwrap_or(rest.len());- format!("{}/Length {}{}", &dict[..i], xml.len(), &rest[end..])- }- None => return None,+ let dict = {+ let i = dict.find("/Length")?;+ let rest = &dict[i + 7..];+ let rest = rest.trim_start();+ let end = rest.find(|c: char| !c.is_ascii_digit()).unwrap_or(rest.len());+ format!("{}/Length {}{}", &dict[..i], xml.len(), &rest[end..])};let mut b = dict.trim().as_bytes().to_vec();b.extend_from_slice(b"\nstream\n");diff --git a/crates/pdf/src/transitions.rs b/crates/pdf/src/transitions.rsindex 0828c7b2e..8f6a864f2 100644--- a/crates/pdf/src/transitions.rs+++ b/crates/pdf/src/transitions.rs@@ -132,7 +132,7 @@ pub fn add_catalog_entries(pdf: &[u8], entries: &str) -> Option<Vec<u8>> {out.push(b'\n');}let at = out.len();- out.extend_from_slice(format!("{root} 0 obj\n{}{entries}{}\nendobj\n", cat[..close].trim(), &cat[close..].trim()).as_bytes());+ out.extend_from_slice(format!("{root} 0 obj\n{}{entries}{}\nendobj\n", cat[..close].trim(), cat[close..].trim()).as_bytes());let xref_at = out.len();out.extend_from_slice(format!("xref\n{root} 1\n{at:010} 00000 n\r\ntrailer\n<</Size {size}/Root {root} 0 R{info}{id}/Prev {prev}>>\nstartxref\n{xref_at}\n%%EOF\n")diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rsindex d58a8b33f..80acb00ef 100644--- a/crates/render/src/lib.rs+++ b/crates/render/src/lib.rs@@ -46,7 +46,7 @@ pub struct Rendered {impl Rendered {pub fn to_straight(&self) -> Vec<u8> {let mut out = self.pixels.clone();- for px in out.chunks_exact_mut(4) {+ for px in out.as_chunks_mut::<4>().0 {let a = px[3] as u32;if a != 0 && a != 255 {for c in &mut px[..3] {@@ -65,7 +65,9 @@ impl Rendered {pub fn to_jpeg(&self, quality: u8) -> Vec<u8> {let rgba = self.to_straight();let rgb: Vec<u8> = rgba- .chunks_exact(4)+ .as_chunks::<4>()+ .0+ .iter().flat_map(|p| {let a = p[3] as u32;let mix = |c: u8| ((c as u32 * a + 255 * (255 - a)) / 255) as u8;@@ -928,7 +930,7 @@ pub fn decode_pixmap_page(bytes: &[u8], page: u32) -> Option<Pixmap> {}if designcraft_images::is_svg(bytes) {let (px, w, h) = designcraft_images::render_svg(bytes, 3000)?;- let data = px.chunks_exact(4).map(|p| vello_cpu::color::PremulRgba8 { r: p[0], g: p[1], b: p[2], a: p[3] }).collect();+ let data = px.as_chunks::<4>().0.iter().map(|p| vello_cpu::color::PremulRgba8 { r: p[0], g: p[1], b: p[2], a: p[3] }).collect();return Some(Pixmap::from_parts(data, w.min(u16::MAX as u32) as u16, h.min(u16::MAX as u32) as u16));}let img = designcraft_images::decode_rgba(bytes)?;@@ -1033,7 +1035,7 @@ pub fn render_pdf_page(bytes: &[u8], page: usize, max_side: u32) -> Option<Pixmalet pm = hayro::render(p, &hayro::RenderCache::new(), &hayro::hayro_interpret::InterpreterSettings::default(), &rs);let (pw, ph) = (pm.width(), pm.height());let data: Vec<vello_cpu::color::PremulRgba8> =- pm.data_as_u8_slice().chunks_exact(4).map(|c| vello_cpu::color::PremulRgba8 { r: c[0], g: c[1], b: c[2], a: c[3] }).collect();+ pm.data_as_u8_slice().as_chunks::<4>().0.iter().map(|c| vello_cpu::color::PremulRgba8 { r: c[0], g: c[1], b: c[2], a: c[3] }).collect();Some(Pixmap::from_parts(data, pw, ph))}@@ -1066,7 +1068,7 @@ pub fn pdf_page_box(bytes: &[u8], page: usize, kind: &str) -> Option<(f64, f64,/// deficiencies) through the active colour settings' proof table.pub fn proof_view(img: &mut Rendered, setup: &designcraft_color::cms::ProofSetup) {let lut = designcraft_color::cms::active().proof_lut(setup);- for px in img.pixels.chunks_exact_mut(4) {+ for px in img.pixels.as_chunks_mut::<4>().0 {let a = px[3];if a == 0 {continue;@@ -1091,7 +1093,7 @@ fn blend_space_view(img: &mut Rendered, area: Rect) {let (x1, y1) = ((area.x1.ceil() as i64).clamp(0, w), (area.y1.ceil() as i64).clamp(0, h));for y in y0..y1 {let row = &mut img.pixels[((y * w + x0) * 4) as usize..((y * w + x1) * 4) as usize];- for px in row.chunks_exact_mut(4) {+ for px in row.as_chunks_mut::<4>().0 {let a = px[3];if a == 0 {continue;@@ -1107,7 +1109,7 @@ fn blend_space_view(img: &mut Rendered, area: Rect) {}pub fn separation_view(img: &mut Rendered, plate: Option<u8>, ink_limit: Option<f32>) {- for px in img.pixels.chunks_exact_mut(4) {+ for px in img.pixels.as_chunks_mut::<4>().0 {let a = px[3] as f32 / 255.0;// Composite over paper white, then separate.let ch = |v: u8| (v as f32 / 255.0) + (1.0 - a);diff --git a/crates/render/tests/effects.rs b/crates/render/tests/effects.rsindex 02c8ed54b..a664c27a8 100644--- a/crates/render/tests/effects.rs+++ b/crates/render/tests/effects.rs@@ -57,7 +57,7 @@ fn golden(name: &str, img: &Rendered) {assert_eq!((want.width(), want.height()), (img.width, img.height), "{name}: size");let got = img.to_straight();let (mut bad, mut sum, mut worst) = (0usize, 0u64, 0u8);- for (a, b) in got.chunks_exact(4).zip(want.as_raw().chunks_exact(4)) {+ for (a, b) in got.as_chunks::<4>().0.iter().zip(want.as_raw().as_chunks::<4>().0) {let d = a.iter().zip(b).map(|(x, y)| x.abs_diff(*y)).max().unwrap();sum += d as u64;worst = worst.max(d);diff --git a/crates/textimport/src/tagged.rs b/crates/textimport/src/tagged.rsindex f88e9c94b..e3ae05ae4 100644--- a/crates/textimport/src/tagged.rs+++ b/crates/textimport/src/tagged.rs@@ -75,8 +75,12 @@ pub fn tagged_text(doc: &Document, story: &Story) -> String {fn decode(bytes: &[u8]) -> String {if bytes.starts_with(&[0xFF, 0xFE]) || bytes.starts_with(&[0xFE, 0xFF]) {let le = bytes[0] == 0xFF;- let units: Vec<u16> =- bytes[2..].chunks_exact(2).map(|c| if le { u16::from_le_bytes([c[0], c[1]]) } else { u16::from_be_bytes([c[0], c[1]]) }).collect();+ let units: Vec<u16> = bytes[2..]+ .as_chunks::<2>()+ .0+ .iter()+ .map(|c| if le { u16::from_le_bytes([c[0], c[1]]) } else { u16::from_be_bytes([c[0], c[1]]) })+ .collect();return String::from_utf16_lossy(&units);}String::from_utf8_lossy(bytes).trim_start_matches('\u{FEFF}').to_string()