This style guide ensures consistency across the codebase by outlining formatting rules, naming conventions, and Rust-specific practices used in the hexaFn project.
- Prioritize readability and maintainability
- Follow idiomatic Rust patterns and conventions
- Keep functions short, pure, and focused
- Document public items with clear and concise comments
- Each module resides in its own file
- File names use
snake_case(e.g.,data_parser.rs) - Group related modules into folders
- Avoid deep nesting where possible
| Item | Convention | Example |
|---|---|---|
| Variables | snake_case |
user_name |
| Functions | snake_case |
fetch_data() |
| Structs | CamelCase |
UserProfile |
| Enums | CamelCase |
ResponseStatus |
| Traits | CamelCase |
Serializable |
| Constants | SCREAMING_SNAKE_CASE |
MAX_RETRIES |
- Use
rustfmtwith the default configuration - Run
cargo fmtbefore pushing code - Never manually align comments or long lines
- Test modules reside under the same file, inside
#[cfg(test)] - Name test functions clearly:
test_successful_login() - Use
assert_eq!,assert!, or result-based matching
- Use
Result<T, E>and proper error propagation - Prefer descriptive custom error types with
thiserror - Avoid panics in library code
- Use
///for public documentation - Use
//for inline developer comments - Avoid commented-out code
- Enforce with
cargo clippy - Fix all warnings unless explicitly justified
- Common lints to enable:
clippy::unwrap_usedclippy::expect_usedclippy::wildcard_imports
Consistent style improves collaboration and makes onboarding easier. Stick to this guide for clean, professional code.