语言设计: Rust 的几乎规则
(灵感来自 Almost Rules.)
语法
:
后跟一个类型
- except inside struct initializers, where it is followed by a value
- except function result types, which are preceded by
->
泛型使用 <>
- except in expression contexts, which uses
::<>
调用使用 ()
- except where
{}
or[]
is used, because “they convey important information”- except for macro invocations, where
()
,{}
,[]
are equivalent and interchangeable
- except for macro invocations, where
T {}
初始化结构体
- except inside an
if
, where{
starts a branch
Rust 没有 varargs
- except for
extern
functions - except for macros
let
引入绑定
- except in pattern matching, where
let
is implied- except if there is a identifier with that name in scope, then it refers to it
- except if the identifier is only a
let
, not aconst
- except if the identifier is only a
- except in macro pattern matching, where identifiers are matched verbatim
- except if there is a identifier with that name in scope, then it refers to it
语义
有总序的类型实现 Eq
和 Ord
- except
f64
andf32
, which do not
结构体初始化器使用临时生命周期扩展
- except tuple structs
- except when using curly braces to initialize tuple structs
你也许感兴趣的:
- Android 全力押注 Rust,Linux 却在原地踏步?谷歌:用 Rust 重写固件太简单了!
- C 语言老将从中作梗,Rust for Linux 项目内讧升级!核心维护者愤然离职:不受尊重、热情被消耗光
- 从电梯故障到编程新宠,Rust为何连续七年称霸「最受推崇语言」
- 【外评】不要把 Rust 写成 Java
- 美国国防部建议将C代码转换为Rust
- 【外评】Why Not Rust?
- 【外评】 我使用(并喜爱)Rust 已经有 10 年了, 以下是它让我失望的地方
- 【外评】为什么我希望不要让 Rust 锈化一切?
- 【外评】Rust 版的 Linux 文件系统
- Vue诞生10年,创始人尤雨溪推动“锈化”——通过Rust提升Web基础设施性能
你对本文的反应是: