Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Naming

The standard library serves as the de facto standard for naming conventions in Rust. An effort has been made to formalize the conventions through the RFC 43 and later in the Rust API Guidelines.

The basic rule (C-CASE) consists in using:

  • UpperCamelCase for types, traits, enum variants, and generic type parameters,
  • snake_case for functions, methods, macros, variables, and modules,
  • SCREAMING_SNAKE_CASE for statics, constants, and generic constant parameters,
  • 'lowercase for lifetimes.

The Rust API Guidelines also prescribes more precise naming conventions for particular constructs:

The basic rule (C-CASE) is checked by the compiler (with the nonstandard_style lint set).

In addition to the compiler, the clippy tool can help in adopting naming conventions with the style lint category. For example, the wrong_self_convention lint checks the consistency between conversion method names and their receiver types (self, &self, &mut self) according to (C-CONV).

Development of a secure application MUST follow the naming conventions outlined in the Rust API Guidelines.

References