@coder-rust-conventions
<skill_overview> 编写惯用的、可读的和可维护的 Rust 编写新的 Rust 代码 审查命名和样式 重构惯用模式 设置格式和 lint 规则 Rust API 指南 rustfmt Clippy </skill_overview> <naming_conventions> 函数、变量、模块、文件 类型、特征、枚举、枚举变体 常量、静态项 使用 as_* 进行廉价转换 使用 to_* 进行可能昂贵的转换</naming_conventions> 始终在提交之前运行Cargo fmt 优先使用尾随逗号以减少差异噪音 避免手动对齐;让 rustfmt决定 <ownership_and_borrowing> 更喜欢借用而不是克隆 将 &str 或 &[T] 作为只读输入 使用迭代器而不是基于索引的循环 当调用者应该拥有数据时返回拥有的值 fn find_user(name: &str, users: &[User]) -> Option<&User> { /* ... */ } </ownership_and_borrowing> <pattern_matching> 使用详尽匹配枚举 避免 catch-all _ 除非确实无法访问 使用 if let / while let 进行单变体匹配 </pattern_matching> <anti_patterns> 避免在非测试代码中展开/期望 不要克隆以静默借用检查器 避免大型可变共享状态 </anti_patterns>
<skill_overview> 编写惯用的、可读的和可维护的 Rust 编写新的 Rust 代码 审查命名和样式 重构惯用模式 设置格式和 lint 规则 Rust API 指南 rustfmt Clippy </skill_overview> <naming_conventions> 函数、变量、模块、文件 类型、特征、枚举、枚举变体 常量、静态项 使用 as_* 进行廉价转换 使用 to_* 进行可能昂贵的转换</naming_conventions> 始终在提交之前运行Cargo fmt 优先使用尾随逗号以减少差异噪音 避免手动对齐;让 rustfmt决定 <ownership_and_borrowing> 更喜欢借用而不是克隆 将 &str 或 &[T] 作为只读输入 使用迭代器而不是基于索引的循环 当调用者应该拥有数据时返回拥有的值 fn find_user(name: &str, users: &[User]) -> Option<&User> { /* ... */ } </ownership_and_borrowing> <pattern_matching> 使用详尽匹配枚举 避免 catch-all _ 除非确实无法访问 使用 if let / while let 进行单变体匹配 </pattern_matching> <anti_patterns> 避免在非测试代码中展开/期望 不要克隆以静默借用检查器 避免大型可变共享状态 </anti_patterns>