语言设计: 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
externfunctions - except for macros
let 引入绑定
- except in pattern matching, where
letis 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
f64andf32, which do not
结构体初始化器使用临时生命周期扩展
- except tuple structs
- except when using curly braces to initialize tuple structs
你也许感兴趣的:
- 编程语言 Rust 的几个核心问题
- Rust并非系统编程的未来——它只是炒作周期
- Rust在Android中的应用:内存安全漏洞密度较C/C++降低了1000倍
- 用Rust重写的 coreutils 漏洞导致Ubuntu 25.10自动更新功能失效
- Debian强制要求APT采用Rust语言,重塑Ubuntu及其他Linux发行版
- Rust 防御性编程模式
- Debian的APT即将强制要求Rust支持:各移植版本需适配或面临淘汰
- Git 采用 SHA-256、Rust、LLM 等技术动态
- 即将推出的适用于内核开发的Rust语言特性
- 编程语言 Rust 与 Carbon 的对比
你对本文的反应是: