[Rust] 命名习惯

通用习惯

CamelCase: 首位是大写字母的单词,没有分隔符;

snake_case: 使用下划线作为分隔符,小写单词;

SCREAMING_SNAKE_CASE: 使用下划线作为分隔符,大写单词;

缩写被认为是一个单词: 在 CamelCase 中,使用 Uuid 而不是 UUID

snake_caseSCREAMING_SNAKE_CASE 中 一个字母(除非是最后的单词)永远不会被当成一个单词,

所以使用 btree_map 而不是 b_tree_map

但是使用 PI_2 而不是 PI2 (这点儿要注意)。

元素习惯
Cratessnake_case (but prefer single word)
Modulessnake_case
TypesCamelCase
TraitsCamelCase
Enum variantsCamelCase
Functionssnake_case
Methodssnake_case
General constructorsnew or with_more_details
Conversion constructorsfrom_some_other_type
Local variablessnake_case
Static variablesSCREAMING_SNAKE_CASE
Constant variablesSCREAMING_SNAKE_CASE
Type parametersconcise CamelCase, usually single uppercase letter: T
Lifetimesshort, lowercase: 'a

getter 和 setter

  • getter: foo(&self) -> &T
  • setter: set_foo(&self, val: T)

参照