Skip to content

refactor: rust best practices audit — 15 issues across workspace #162

@crrow

Description

@crrow

Summary

基于 rust-skills 179 条规则对整个 workspace 的审查,发现 15 个可改进项。

CRITICAL (2)

  • crates/gateway/src/proxy.rs:102-104.expect() 在请求处理路径可导致 panic,改用 snafu 错误传播
  • Cargo.toml — 缺少 [profile.release] 优化配置(LTO、codegen-units=1、strip)

HIGH (4)

  • crates/gateway/src/proxy.rs:60-61,74,85 — 不必要的 clone,用 req.into_parts() 替代
  • crates/gateway/src/proxy.rs:62-64 — body 读取失败被 unwrap_or_default() 静默吞掉,且无大小限制
  • crates/core/src/service_map.rs:12-18 — ServiceMap trait 返回 Vec<String> 导致每次调用强制 clone
  • crates/core/src/service_map.rs:47standalone() 中冗余 clone

MEDIUM (6)

  • Cargo.toml — 缺少 missing_docs = "warn" lint
  • Cargo.toml — 缺少 [profile.bench] 配置
  • crates/gateway/src/proxy.rs:94-99 — 无效响应头被静默丢弃,无日志
  • crates/gateway/src/proxy.rs:38-105 — proxy 函数过长,拆分为辅助函数
  • crates/client-wasm/Cargo.toml — snafu 0.8 vs workspace 0.9 版本不一致
  • crates/core/src/service_map.rs:33const fn new() + Vec 兼容性

LOW (3)

  • 热路径小函数添加 #[inline]
  • 热类型添加 mem::size_of assertion 防止膨胀回归
  • 评估 StaticServiceMap 是否需要升级到 bon::Builder

详细说明

issue.md(repo 根目录)

Acceptance Criteria

  • 所有 CRITICAL 和 HIGH 项修复
  • cargo check && cargo test && cargo clippy 全部通过

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:claudeWork done by Claude agentrefactorCode refactoring

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions