К основному содержанию
скилл CX Codex

rust-reviewer — скилл для Claude Code: обзор Rust-кода и установка

Скилл rust-reviewer для Claude Code и Codex проверяет Rust-код на ошибки владения, работы с временами жизни и обработки ошибок. Запускает полный обзор проекта, включая аудит unsafe и проверку идиоматичного Rust.

Apache-2.0 ★ 423 обновлён 2026-11-16

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add relatedb/relate --skill rust-reviewer -a claude-code
Открыть на GitHub

Что делает rust-reviewer

rust-reviewer проверяет Rust-проект на проблемы с владением и заимствованием, временами жизни, типами Result и Option, небезопасным кодом и идиоматичным стилем. Проект распознаётся по Cargo.toml, файлам .rs или каталогам src/ и tests/.

Скилл анализирует весь проект без интерактивного выбора. Он отмечает, например, лишний clone(), неоправданный unwrap() в библиотечном коде и разыменование сырого указателя без проверки. Для разбора проекта учитываются редакция Rust, тип проекта, зависимости, тесты через cargo test и линтер clippy.

Проверка ориентирована на ревью кода проекта; для ревью Rust API предназначен rust-api-reviewer, а для Go — go-reviewer.

Какие задачи решает

  • найти лишнее копирование данных через clone()
  • проверить аннотации времён жизни и заимствования
  • заметить unwrap() и panic! при обработке ошибок
  • провести аудит разыменований указателей и transmute
  • выявить отступления от идиоматичного Rust

Примеры запросов агенту

  • Проведи ревью Rust-проекта на владение и заимствование.
  • Проверь времена жизни и обработку ошибок в этом проекте.
  • Проведи аудит блоков unsafe и проверь идиоматичный Rust.

Как установить rust-reviewer

1Через Skills CLI (Vercel)

npx skills add relatedb/relate --skill rust-reviewer -a claude-code

2Вручную: положить файлы

~/.claude/skills/rust-reviewer/SKILL.md

Папка скилла целиком; для одного проекта — .claude/skills/rust-reviewer/

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Вопросы о rust-reviewer

Как установить rust-reviewer в Claude Code?

Выполни npx skills add relatedb/relate --skill rust-reviewer -a claude-code. Файл скилла находится по пути ~/.claude/skills/rust-reviewer/SKILL.md.

Что делает rust-reviewer?

Скилл проверяет Rust-код на проблемы владения, времён жизни, обработки ошибок и безопасности unsafe. Также он ищет неидиоматичные конструкции.

Чем rust-reviewer отличается от rust-api-reviewer?

rust-reviewer предназначен для ревью Rust-проекта. Для ревью Rust API используется rust-api-reviewer.

Исходный текст

SKILL.md · Apache-2.0
---
name: rust-reviewer
description: |
  WHEN: Rust project review, ownership/borrowing, error handling, unsafe code, performance
  WHAT: Ownership patterns + Lifetime analysis + Error handling (Result/Option) + Unsafe audit + Idiomatic Rust
  WHEN NOT: Rust API → rust-api-reviewer, Go → go-reviewer
---

# Rust Reviewer Skill

## Purpose
Reviews Rust code for ownership, lifetimes, error handling, safety, and idiomatic patterns.

## When to Use
- Rust project code review
- Ownership/borrowing review
- Lifetime annotation review
- Unsafe code audit
- Error handling patterns

## Project Detection
- `Cargo.toml` in project root
- `.rs` files
- `src/lib.rs` or `src/main.rs`
- `tests/` directory

## Workflow

### Step 1: Analyze Project
```
**Rust Edition**: 2021
**Type**: Library / Binary
**Dependencies**: Key crates
**Testing**: cargo test
**Linter**: clippy
```

### Step 2: Run Full Review
Run a full review covering all areas below: ownership and borrowing, lifetimes and references, error handling (Result/Option), unsafe code audit, and idiomatic Rust. This skill runs headless, so no interactive selection — review everything by default.

## Detection Rules

### Ownership & Borrowing
| Check | Recommendation | Severity |
|-------|----------------|----------|
| Unnecessary clone() | Borrow instead | MEDIUM |
| &String parameter | Use &str | MEDIUM |
| Vec ownership transfer | Consider slice | MEDIUM |
| Excessive Rc/Arc | Restructure ownership | MEDIUM |

```rust
// BAD: Unnecessary clone
fn process(data: Vec<String>) {
    for item in data.clone().iter() {  // Clone not needed!
        println!("{}", item);
    }
}

// GOOD: Borrow
fn process(data: &[String]) {
    for item in data {
        println!("{}", item);
    }
}

// BAD: &String parameter
fn greet(name: &String) {
    println!("Hello, {}", name);
}

// GOOD: &str parameter (more flexible)
fn greet(name: &str) {
    println!("Hello, {}", name);
}

// BAD: Taking ownership unnecessarily
fn sum(numbers: Vec<i32>) -> i32 {
    numbers.iter().sum()
}

// GOOD: Borrow slice
fn sum(numbers: &[i32]) -> i32 {
    numbers.iter().sum()
}
```

### Lifetimes
| Check | Recommendation | Severity |
|-------|----------------|----------|
| Missing lifetime annotation | Add explicit lifetime | HIGH |
| 'static overuse | Use specific lifetime | MEDIUM |
| Lifetime in struct | Consider ownership | MEDIUM |
| Complex lifetime bounds | Simplify if possible | LOW |

```rust
// BAD: Missing lifetime
struct Parser {
    input: &str,  // Error: missing lifetime
}

// GOOD: Explicit lifetime
struct Parser<'a> {
    input: &'a str,
}

impl<'a> Parser<'a> {
    fn new(input: &'a str) -> Self {
        Parser { input }
    }

    fn parse(&self) -> Result<Ast<'a>, Error> {
        // ...
    }
}

// BAD: 'static when not needed
fn process(data: &'static str) {
    // Requires static lifetime!
}

// GOOD: Generic lifetime
fn process(data: &str) {
    // Works with any lifetime
}

// Consider: Ownership instead of lifetime
struct Config {
    name: String,  // Owned, no lifetime needed
}
```

### Error Handling
| Check | Recommendation | Severity |
|-------|----------------|----------|
| unwrap() in library | Return Result | HIGH |
| expect() without message | Add descriptive message | MEDIUM |
| panic! for recoverable | Return Err | HIGH |
| No custom error type | Define error enum | MEDIUM |

```rust
// BAD: unwrap in library code
pub fn parse_config(path: &str) -> Config {
    let content = fs::read_to_string(path).unwrap();  // Will panic!
    serde_json::from_str(&content).unwrap()
}

// GOOD: Return Result
pub fn parse_config(path: &str) -> Result<Config, ConfigError> {
    let content = fs::read_to_string(path)
        .map_err(|e| ConfigError::IoError(e))?;
    serde_json::from_str(&content)
        .map_err(|e| ConfigError::ParseError(e))
}

// GOOD: Custom error type
#[derive(Debug, thiserror::Error)]
pub enum ConfigError {
    #[error("failed to read config file: {0}")]
    IoError(#[from] std::io::Error),

    #[error("failed to parse config: {0}")]
    ParseError(#[from] serde_json::Error),

    #[error("missing required field: {0}")]
    MissingField(String),
}

// BAD: expect without message
let value = map.get("key").expect("failed");

// GOOD: Descriptive expect
let value = map.get("key")
    .expect("config must contain 'key' field");
```

### Option Handling
| Check | Recommendation | Severity |
|-------|----------------|----------|
| if let Some + else | Use map_or/unwrap_or | LOW |
| Nested Options | Use and_then/flatten | MEDIUM |
| match for single case | Use if let | LOW |

```rust
// BAD: Verbose Option handling
let result = match value {
    Some(v) => v.to_string(),
    None => "default".to_string(),
};

// GOOD: Using combinators
let result = value
    .map(|v| v.to_string())
    .unwrap_or_else(|| "default".to_string());

// Or even simpler
let result = value.map_or("default".to_string(), |v| v.to_string());

// BAD: Nested Options
let result: Option<Option<i32>> = Some(Some(42));
let value = match result {
    Some(Some(v)) => v,
    _ => 0,
};

// GOOD: Flatten
let value = result.flatten().unwrap_or(0);

// Using and_then for chaining
let value = get_user(id)
    .and_then(|user| user.profile)
    .and_then(|profile| profile.avatar)
    .map(|avatar| avatar.url);
```

### Unsafe Code
| Check | Recommendation | Severity |
|-------|----------------|----------|
| Unnecessary unsafe | Remove if safe alternative | HIGH |
| No safety comment | Document invariants | HIGH |
| Raw pointer dereference | Validate pointer | CRITICAL |
| Transmute usage | Use safe cast if possible | CRITICAL |

```rust
// BAD: Unsafe without documentation
unsafe fn get_value(ptr: *const i32) -> i32 {
    *ptr
}

// GOOD: Documented unsafe
/// Gets the value at the given pointer.
///
/// # Safety
///
/// - `ptr` must be valid and properly aligned
/// - `ptr` must point to initialized memory
/// - The memory must not be mutated while this reference exists
unsafe fn get_value(ptr: *const i32) -> i32 {
    debug_assert!(!ptr.is_null(), "ptr must not be null");
    *ptr
}

// BAD: Transmute for casting
let bytes: [u8; 4] = unsafe { std::mem::transmute(value) };

// GOOD: Safe alternative
let bytes = value.to_ne_bytes();

// Encapsulating unsafe in safe API
pub struct Buffer {
    ptr: *mut u8,
    len: usize,
}

impl Buffer {
    /// Creates a new buffer. Safe because we control allocation.
    pub fn new(size: usize) -> Self {
        let ptr = unsafe { alloc(Layout::array::<u8>(size).unwrap()) };
        Self { ptr, len: size }
    }

    /// Safe accessor - bounds checked
    pub fn get(&self, index: usize) -> Option<u8> {
        if index < self.len {
            // SAFETY: index is bounds-checked above
            Some(unsafe { *self.ptr.add(index) })
        } else {
            None
        }
    }
}
```

### Idiomatic Rust
| Check | Recommendation | Severity |
|-------|----------------|----------|
| C-style loop | Use iterators | LOW |
| Manual index tracking | Use enumerate() | LOW |
| Return in match | Return match expression | LOW |
| Redundant type annotation | Use inference | LOW |

```rust
// BAD: C-style loop
let mut i = 0;
while i < items.len() {
    process(&items[i]);
    i += 1;
}

// GOOD: Iterator
for item in &items {
    process(item);
}

// With index
for (i, item) in items.iter().enumerate() {
    println!("{}: {}", i, item);
}

// BAD: Redundant type
let numbers: Vec<i32> = vec![1, 2, 3];
let sum: i32 = numbers.iter().sum();

// GOOD: Type inference
let numbers = vec![1, 2, 3];
let sum: i32 = numbers.iter().sum();  // Only needed here

// BAD: Return in match arms
fn classify(n: i32) -> &'static str {
    match n {
        0 => { return "zero"; }
        _ if n > 0 => { return "positive"; }
        _ => { return "negative"; }
    }
}

// GOOD: Match as expression
fn classify(n: i32) -> &'static str {
    match n {
        0 => "zero",
        _ if n > 0 => "positive",
        _ => "negative",
    }
}
```

## Response Template
```
## Rust Code Review Results

**Project**: [name]
**Rust Edition**: 2021 | **Clippy**: Enabled

### Ownership & Borrowing
| Status | File | Issue |
|--------|------|-------|
| MEDIUM | parser.rs:45 | Unnecessary clone() |

### Lifetimes
| Status | File | Issue |
|--------|------|-------|
| HIGH | cache.rs:23 | Missing lifetime on struct field |

### Error Handling
| Status | File | Issue |
|--------|------|-------|
| HIGH | lib.rs:67 | unwrap() in public function |

### Unsafe
| Status | File | Issue |
|--------|------|-------|
| CRITICAL | ffi.rs:12 | Unsafe block without safety comment |

### Recommended Actions
1. [ ] Replace clone() with borrowing
2. [ ] Add lifetime annotations to Cache struct
3. [ ] Return Result instead of panicking
4. [ ] Document all unsafe blocks with safety invariants
```

## Best Practices
1. **Ownership**: Borrow when possible, clone when needed
2. **Lifetimes**: Explicit > implicit, owned > referenced
3. **Errors**: thiserror for libs, anyhow for apps
4. **Unsafe**: Minimize, document, encapsulate in safe API
5. **Clippy**: Run with `cargo clippy -- -W clippy::pedantic`

## Integration
- `rust-api-reviewer`: Web framework patterns
- `security-scanner`: Rust security audit
- `perf-analyzer`: Performance profiling

© relatedb · Apache-2.0 · relatedb/relate

Похожие скиллы

Все скиллы по теме «Код-ревью и рефакторинг» →
rust-skills leonardomso 265 правил написания идиоматичного Rust по 26 категориям. Загружается командой /rust-skills перед генерацией или ревью кода. CX Codex +1 7 400установок rust-patterns affaan-m Скилл rust-patterns задаёт правила идиоматичного Rust: управление владением, типизированные ошибки, сопоставление с образцом и трейты. Пригодится при написании, рефакторинге и ревью Rust-кода. CX Codex +1 7 000установок rust-call-graph actionbook Скилл rust-call-graph строит граф вызовов функций Rust через LSP: кто вызывает функцию и что вызывает она. Пригодится при разборе чужого кода и оценке последствий правок. CX Codex +1 3 600установок rust-symbol-analyzer actionbook Скилл rust-symbol-analyzer для Claude Code показывает структуру Rust-проекта через LSP-символы: модули, структуры, трейты, функции. Помогает разобраться в чужом крейте. CX Codex +1 3 500установок rust-best-practices morganlinton Скилл rust-best-practices для Claude Code помогает писать, проверять и объяснять код на Rust. Активируется при упоминании Rust, Cargo, .rs, borrow checker, clippy или rustfmt. CX Codex +1 1 100установок rust-review morganlinton Скилл rust-review для Claude Code проверяет Rust-код и выдаёт приоритетный отчёт с нарушенными правилами и вариантами исправления. Запускается по просьбе проверить файл, модуль, крейт или pull request. CX Codex +1 1 000установок

Из того же набора18

Весь набор →
neo4j-query-workload-skill Скилл neo4j-query-workload-skill для Claude Code наращивает набор запросов к графовой базе по одному требованию за раунд. Он проверяет новые запросы на данных и выявляет регрессии в уже проверенной нагрузке. CX Codex +1 ★ 423звёзд репо relate Помогает подключать в JVM-приложения локальную графовую базу Relate и выполнять запросы на Cypher. Срабатывает при работе с Java- и Kotlin-кодом, который создаёт или использует такую базу. CX Codex +1 ★ 423звёзд репо relate Помогает писать Python-код для локальной графовой базы Relate с запросами openCypher. Подключается к задачам создания базы, выполнения запросов Cypher и обработки результатов. CX Codex +1 ★ 423звёзд репо relate Помогает писать JavaScript и TypeScript-код для локальной графовой базы Relate с запросами openCypher. Он охватывает подключение, транзакции и разбор результатов. CX Codex +1 ★ 423звёзд репо agent-backlog-autopilot Скилл agent-backlog-autopilot для Claude Code проводит одну задачу из агентского бэклога от выбора карточки до PR. После зелёных draft-проверок он ждёт, пока человек разрешит сделать PR готовым к ревью. CX Codex +1 ★ 423звёзд репо stellar-code-quality-review Скилл stellar-code-quality-review для Claude Code строго проверяет поддерживаемость кода, качество абстракций и рост файлов. Запускает поэтапный аудит изменений и связанных с ними участков. CX Codex +1 ★ 423звёзд репо stellar-structure Субагент stellar-structure для Claude Code, который проверяет размер модулей, декомпозицию и размещение слоёв по брифу. Запускается конвейером stellar-review при проверке кода. CX Codex +1 ★ 423звёзд репо stellar-branching Субагент stellar-branching для Claude Code проверяет ветвления, условные конструкции и разрастание запутанной логики. Его запускает конвейер stellar-review с подготовленным брифом. CX Codex +1 ★ 423звёзд репо

Спонсоры проекта

Компании, которые помогают держать аналитику открытой