语言设计: 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
你也许感兴趣的:
- Rust 中的奇怪表达式
- 为什么 Rust 编译器这么慢?
- 微软发布用Rust编写的Linux版经典MS-DOS编辑器
- OpenAI 将用 Rust 重建 Codex CLI,放弃之前的 TypeScript 版本
- bzip2 crate 从 C 切换到 100% rust
- Rust 比 C 更快吗?
- 【程序员搞笑图片】Rust:愿者上钩
- 对 Rust 10 年的押注以及我对未来的期待
- 如何处理 Rust 依赖项
- 在 Rust 中写入未初始化的缓冲区
你对本文的反应是: