From cc3be1ec38702150af4cc33f842598060c8c1579 Mon Sep 17 00:00:00 2001 From: Edouard Vanbelle Date: Fri, 21 Aug 2026 14:27:42 +0200 Subject: [PATCH] refactor: apply clippy recos for rustc 1.98.0 --- clippy.toml | 28 +++++++++++++++++++ examples/bench_round14_queries.rs | 8 ++++-- .../repositories/pg/face_pg_repository.rs | 13 +++++++-- 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 clippy.toml diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 00000000..a59d2fd9 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,28 @@ +# Clippy configuration overrides. Kept minimal — each entry documents +# what it's for and when it should be revisited. + +# `clippy::result_large_err` — raise the "big Err variant" ceiling to +# 512 bytes. +# +# Rationale: axum handler signatures shaped as +# `Result` (or `AppError` variants +# that wrap `axum::response::Response`) naturally exceed the default +# 128-byte threshold. `Response` carries a `HeaderMap` (~256 B inline) +# + status + body + extensions; a handful of handlers land in that +# range without doing anything wrong. Fighting the lint per-handler +# with `#[allow]` on every one is churn for zero runtime benefit — +# these Results are constructed on the stack once per request and +# never nested in a hot inner loop. +# +# 512 B keeps the lint's protective value: it still fires on genuinely +# oversized Err variants (embedded `Vec` blobs, avatar payloads, +# large enum aggregates) that WOULD be worth boxing. +# +# Revisit if: +# * A future refactor slims axum Response OR extracts a small error +# enum with an IntoResponse impl across the handler layer — then +# drop this override back to the default 128. +# * A specific handler exceeds 512 B and clippy re-fires — deal with +# that handler individually (boxed error / small enum) rather than +# raising the ceiling further. +large-error-threshold = 512 diff --git a/examples/bench_round14_queries.rs b/examples/bench_round14_queries.rs index c71e58cb..4fd21a62 100644 --- a/examples/bench_round14_queries.rs +++ b/examples/bench_round14_queries.rs @@ -43,9 +43,13 @@ fn stats(mut s: Vec) -> (f64, f64, f64) { /// Mirror of `face_pg_repository::bytes_to_embedding` — the per-face /// `Vec` decode the BEFORE path pays for a column it never reads. +/// Kept byte-for-byte identical to the shipped path so the benchmark +/// measures apples-to-apples; `as_chunks` swap matches the source. fn bytes_to_embedding(b: &[u8]) -> Vec { - b.chunks_exact(4) - .map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])) + b.as_chunks::<4>() + .0 + .iter() + .map(|c| f32::from_le_bytes(*c)) .collect() } diff --git a/src/infrastructure/repositories/pg/face_pg_repository.rs b/src/infrastructure/repositories/pg/face_pg_repository.rs index a9a4e12b..260c82df 100644 --- a/src/infrastructure/repositories/pg/face_pg_repository.rs +++ b/src/infrastructure/repositories/pg/face_pg_repository.rs @@ -47,8 +47,17 @@ fn embedding_to_bytes(e: &[f32]) -> Vec { } fn bytes_to_embedding(b: &[u8]) -> Vec { - b.chunks_exact(4) - .map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])) + // `as_chunks::<4>` (stable since Rust 1.88) hands back `&[[u8; 4]]` + // typed at the array level, so the closure gets a `&[u8; 4]` and + // the `[c[0], c[1], c[2], c[3]]` array-copy dance from the old + // `chunks_exact(4)` shape collapses to a plain deref. Any trailing + // bytes that aren't a multiple of 4 land in `.1` and are dropped + // — same semantics as `chunks_exact` which iterated only the + // aligned prefix. + b.as_chunks::<4>() + .0 + .iter() + .map(|c| f32::from_le_bytes(*c)) .collect() }