docs: add Rust module organization guidelines to AGENTS.md
This commit is contained in:
@@ -87,6 +87,23 @@ For multi-step tasks, state a brief plan:
|
|||||||
- 优先使用 `Result` 处理错误,避免 `unwrap()`
|
- 优先使用 `Result` 处理错误,避免 `unwrap()`
|
||||||
- 所有权规则:不使用 `&mut` 时不用,引用必须合法
|
- 所有权规则:不使用 `&mut` 时不用,引用必须合法
|
||||||
|
|
||||||
|
**模块组织**
|
||||||
|
- 按功能领域组织模块(一个模块一个职责)
|
||||||
|
- 功能相关和相似的代码归入同一模块
|
||||||
|
- 使用 Rust 新风格模块结构:`foo.rs` 作为模块根,子模块在 `foo/bar.rs`,**不使用 `mod.rs`**
|
||||||
|
- 示例:
|
||||||
|
```
|
||||||
|
src/
|
||||||
|
lib.rs # crate 根
|
||||||
|
types.rs # mod types
|
||||||
|
provider.rs # mod provider (根)
|
||||||
|
provider/
|
||||||
|
openai.rs # provider::openai
|
||||||
|
cycle.rs # mod cycle (根)
|
||||||
|
cycle/
|
||||||
|
retry.rs # cycle::retry
|
||||||
|
```
|
||||||
|
|
||||||
**测试文件**: 内联测试(`#[cfg(test)] mod tests {}`)或 `tests/` 目录
|
**测试文件**: 内联测试(`#[cfg(test)] mod tests {}`)或 `tests/` 目录
|
||||||
|
|
||||||
**依赖管理**: `Cargo.toml`,语义化版本
|
**依赖管理**: `Cargo.toml`,语义化版本
|
||||||
|
|||||||
Reference in New Issue
Block a user