2.2.1 命名约定

命名约定 — Comprehensive Rust

译文 · 基于 Comprehensive Rust

原文链接: https://google.github.io/comprehensive-rust/idiomatic/foundations-api-design/predictable-api/naming-conventions.html

2.2.1 命名约定

  • 可读性与可预测性的一个核心要素,是函数名的构成方式。

正式且一致应用的命名约定,让开发者能把名称当作领域特定语言,快速理解方法的功能与用例。

Rust 社区很早就形成了命名约定,使得标准库等处大多保持一致。

  • 这里我们将学习 Rust 方法名的常见组成部分,给出标准库中的例子,并附上相关语境。

2.2.1.1 New

01-New — Comprehensive Rust

2.2.1.2 Is

02-Is — Comprehensive Rust

2.2.1.3 Mut

03-Mut — Comprehensive Rust

2.2.1.4 With:构造函数

04-With:构造函数 — Comprehensive Rust

2.2.1.5 With:复制并修改

05-With:复制并修改 — Comprehensive Rust

2.2.1.6 With:闭包

06-With:闭包 — Comprehensive Rust

2.2.1.7 Try

07-Try — Comprehensive Rust

2.2.1.8 From

08-From — Comprehensive Rust

2.2.1.9 Into

09-Into — Comprehensive Rust

2.2.1.10 To

10-To — Comprehensive Rust

2.2.1.11 As 与 Ref

11-As 与 Ref — Comprehensive Rust

2.2.1.12 By

12-By — Comprehensive Rust

2.2.1.13 练习

13-练习 — Comprehensive Rust

最后修改 August 11, 2026: 更新 (70a5af133)