[Rust] 命名习惯
通用习惯
CamelCase: 首位是大写字母的单词,没有分隔符;
snake_case: 使用下划线作为分隔符,小写单词;
SCREAMING_SNAKE_CASE: 使用下划线作为分隔符,大写单词;
缩写被认为是一个单词: 在 CamelCase 中,使用 Uuid 而不是 UUID;
在 snake_case 和 SCREAMING_SNAKE_CASE 中 一个字母(除非是最后的单词)永远不会被当成一个单词,
所以使用 btree_map 而不是 b_tree_map;
但是使用 PI_2 而不是 PI2 (这点儿要注意)。
| 元素 | 习惯 |
|---|---|
| Crates | snake_case (but prefer single word) |
| Modules | snake_case |
| Types | CamelCase |
| Traits | CamelCase |
| Enum variants | CamelCase |
| Functions | snake_case |
| Methods | snake_case |
| General constructors | new or with_more_details |
| Conversion constructors | from_some_other_type |
| Local variables | snake_case |
| Static variables | SCREAMING_SNAKE_CASE |
| Constant variables | SCREAMING_SNAKE_CASE |
| Type parameters | concise CamelCase, usually single uppercase letter: T |
| Lifetimes | short, lowercase: 'a |
getter 和 setter
- getter:
foo(&self) -> &T - setter:
set_foo(&self, val: T)