# Rust Naming Conventions
## Rule
Follow RFC 430 naming conventions strictly. The compiler warns on violations — treat these warnings as errors.
## Naming Rules
| Element | Convention | Example |
|---------|-----------|---------|
| Crate | snake_case | `my_library`, `web_server` |
| Module | snake_case | `user_service`, `http_client` |
| Type (struct, enum) | PascalCase | `HttpClient`, `UserProfile` |
| Trait | PascalCase | `Serialize`, `IntoIterator` |
| Function/Method | snake_case | `get_user()`, `is_valid()` |
| Variable | snake_case | `user_count`, `file_path` |
| Constant | SCREAMING_SNAKE_CASE | `MAX_RETRIES`, `DEFAULT_PORT` |
| Static | SCREAMING_SNAKE_CASE | `GLOBAL_CONFIG` |
| Enum variant | PascalCase | `Color::DarkBlue` |
| Type parameter | PascalCase, short | `T`, `E`, `K`, `V` |
| Lifetime | lowercase, short | `'a`, `'ctx`, `'de` |
## Good Examples
```rust
const MAX_CONNECTIONS: u32 = 100;
const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30);
struct HttpClient {
base_url: String,
timeout: Duration,
}
enum ConnectionState {
Connected,
Disconnected,
Reconnecting { attempt: u32 },
}
trait Repository {
fn find_by_id(&self, id: &str) -> Option<&User>;
fn save(&mut self, user: User) -> Result<(), SaveError>;
}
fn parse_config_file(path: &Path) -> Result<Config, ConfigError> {
let content = std::fs::read_to_string(path)?;
toml::from_str(&content).map_err(ConfigError::Parse)
}
```
## Bad Examples
```rust
// BAD: Wrong casing
struct http_client { ... } // Should be HttpClient
fn GetUser() { ... } // Should be get_user
const maxRetries: u32 = 5; // Should be MAX_RETRIES
enum color { red, blue } // Should be Color { Red, Blue }
// BAD: Abbreviations
struct Usr { ... } // Spell out: User
fn proc_req() { ... } // Spell out: process_request
```
## Enforcement
- Compiler warnings catch most naming violations
- Clippy for additional naming best practices
- `cargo clippy -- -W clippy::module_name_repetitions`