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:
UpperCamelCasefor types, traits, enum variants, and generic type parameters,snake_casefor functions, methods, macros, variables, and modules,SCREAMING_SNAKE_CASEfor statics, constants, and generic constant parameters,'lowercasefor lifetimes.
The Rust API Guidelines also prescribes more precise naming conventions for particular constructs:
(C-CONV)for conversion methods (as_,to_,into_),(C-GETTER)for getters,(C-ITER)for iterator-producing methods,(C-ITER-TY)for iterator types,(C-FEATURE)for feature naming (conditionally enabled functionalities),(C-WORD-ORDER)for word order consistency.
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
- General naming conventions (RFC-430)
- Rust API Guidelines (rust-guidelines)