Back to all reviewers

Prefer Rust structural patterns

zed-industries/zed
Based on 6 comments
Rust

Use Rust's structural patterns to write more idiomatic and maintainable code. This includes: 1. Use early returns to reduce nesting: ```rust // Instead of

Code Style Rust

Reviewer Prompt

Use Rust’s structural patterns to write more idiomatic and maintainable code. This includes:

  1. Use early returns to reduce nesting: ```rust // Instead of if condition { if other_condition { // deep nesting } }

// Prefer if !condition { return } if !other_condition { return } // main logic


2. Leverage pattern matching and destructuring:
```rust
// Instead of
let response = response.body_mut().read_to_end(&mut body).await?;
if response.status().is_success() {
    // handle success
}

// Prefer
let Some((buffer, buffer_position)) = self.buffer.read(cx)
    .text_anchor_for_position(position, cx) 
else { return };
  1. Use Rust’s type system effectively: ```rust // Instead of signature_help_task: Default::default(),

// Prefer signature_help_task: None,


4. Utilize iterator combinators to flatten logic:
```rust
// Instead of
.get_diagnostics(server_id)
    .map(|diag| {
        diag.iter()
            .filter(...)
            .map(...)
            .collect()
    })

// Prefer
.get_diagnostics(server_id)
    .into_iter()
    .flat_map(...)

These patterns improve code readability, reduce complexity, and make the code more maintainable by leveraging Rust’s built-in features effectively.

6
Comments Analyzed
Rust
Primary Language
Code Style
Category

Source Discussions