4.4 类型别名
04-类型别名 — Comprehensive Rust
1分钟内可阅读完
译文 · 基于 Comprehensive Rust
原文链接: https://google.github.io/comprehensive-rust/user-defined-types/aliases.html
4.4 类型别名
类型别名(type alias)为另一类型创建名称。这两种类型可以互换使用。
| |
Newtype 往往是更好的选择,因为它会创建不同的类型。优先使用
struct InventoryCount(usize),而不是type InventoryCount = usize。C 程序员会认出这与
typedef类似。