Back to all reviewers

Prefer simpler code constructs

tokio-rs/axum
Based on 6 comments
Rust

Always opt for simpler, more idiomatic code constructs over complex or verbose alternatives. This includes using built-in Rust patterns instead of manual implementations, leveraging pattern matching for cleaner control flow, using method chaining when it improves readability, and maintaining consistent formatting.

Code Style Rust

Reviewer Prompt

Always opt for simpler, more idiomatic code constructs over complex or verbose alternatives. This includes:

  1. Using built-in Rust patterns instead of manual implementations: ```rust // Instead of .for_each(|(name, value)| { // … implementation });

// Prefer for (name, value) in items { // … implementation }


2. Leveraging pattern matching for cleaner control flow:
```rust
// Instead of
let content_length = req.method().clone();
if content_length > N { ... }

// Prefer
match (content_length, req.method()) {
    (content_length, &(Method::GET | Method::HEAD)) => { ... }
}
  1. Using method chaining when it improves readability: ```rust // Instead of cmd.arg(“–body”); cmd.arg(body);

// Prefer cmd.args(&[”–body”, body]) ```

  1. Maintaining consistent formatting:
    • Group related imports together
    • Avoid mixing inline and non-inline arguments
    • Use consistent line wrapping in documentation

The goal is to write code that is easier to read, maintain, and reason about by leveraging Rust’s built-in constructs and following consistent patterns.

6
Comments Analyzed
Rust
Primary Language
Code Style
Category

Source Discussions