Menu
Coddy logo textTech

Naming Conventions

Part of the Fundamentals section of Coddy's Rust journey — lesson 11 of 75.

In Rust, there are several naming conventions that you should follow to make your code more readable and maintainable. They are widely accepted by the Rust community.

Here are some common naming conventions:

  • Variables should be named using snake_case, which means all lowercase letters with underscores between words. For example: my_variable, calculate_total.
  • Avoid overly short or cryptic names. Choose descriptive names that clearly indicate the purpose of the variable.
  • Names can contain letters, digits and underscores.
  • Names must start with a letter or an underscore _.
  • Basic counters usually use single letter such as i, j, though it's worth noting that more descriptive names might be better when the context is more complex.

Cheat sheet

Rust naming conventions for variables:

  • Use snake_case - all lowercase with underscores between words
  • Choose descriptive names that indicate the variable's purpose
  • Names can contain letters, digits, and underscores
  • Names must start with a letter or underscore _
  • Basic counters can use single letters like i, j

Examples: my_variable, calculate_total

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals