Rust code quality audit based on Apollo best practices
$ARGUMENTS
Audit Rust code quality. Report issues in organized format, then offer to fix.
#[expect(...)] with comment if truly necessary, never bare #[allow(...)]Red flags:
.clone() inside loops - use .cloned() or .copied() on iterator.clone() on large types (Vec<T>, HashMap<K,V>)fn process(s: String) vs fn process(s: &str)&Vec<T> instead of &[T]&String instead of &strPrefer:
&str over String in params&[T] over &Vec<T> in paramsimpl AsRef<T> for flexible APIsRed flags:
.unwrap() or .expect() in non-test codematch for simple Ok/Err -> Some/None conversions (use .ok(), .ok_or())let Ok(x) = expr else { return }if let Some(x) = ... { x } else { default } instead of .unwrap_or()Prefer:
? for error propagationlet Ok(x) = expr else { return Err(...) } for early returns.ok_or_else() / .map_or_else() when allocation neededthiserror for library errors, anyhow only for binariesRed flags:
.collect::<Vec<_>>() then for x in vec.filter().map().collect().fold() for simple sums (use .sum()).iter() vs .into_iter() awareness (prefer .iter() for Copy types)Prefer:
.enumerate() over manual index trackingRed flags:
panic! in library code (use Result)Box<dyn Error> in library APIs (use thiserror)# Errors doc section on fallible functionsanyhow in library codePrefer:
thiserror with descriptive error variants#[from] for wrapping? over verbose match chainsinspect_err() for loggingRed flags:
Box when stack works)#[inline] without benchmark proofBox<dyn Trait> when impl Trait worksor, map_or, unwrap_or (use _else variants)Prefer:
impl Trait (static dispatch) over dyn Trait when possibleCow<'_, str> for maybe-owned dataRed flags:
// TODO without issue link/// docs on public items# Examples, # Errors, # Panics sectionsPrefer:
Red flags:
Option<T> fields for required builder params#[non_exhaustive] on public enumsdyn Trait without Send + Sync in async contextsPrefer:
PhantomData for zero-cost type markersRed flags:
# Rust Quality Audit: [path]
## Critical (must fix)
- [file:line] Category: Description
## Warnings (should fix)
- [file:line] Category: Description
## Suggestions (consider)
- [file:line] Category: Description
## Summary
- X critical, Y warnings, Z suggestions
- Key patterns to address: ...
After reporting, ask: "Fix issues? (all / critical only / skip)"