知识卡片
类型别名保留原有类型
type Bytes = Vec<u8>; 给现有类型另一个名字。把图像编码函数的返回值写成 Bytes 可以强调它在接口中表示字节序列,调用者得到的值仍然具有 Vec<u8> 的类型和方法。别名适用于缩短已有表示的写法。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Fundamental Types 类型别名给现有类型命名 · 查看原书依据
The type keyword can be used like typedef in C++ to declare a new name for an existing type:
参考来源
- 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第02章《Fundamental Types》|类型别名给现有类型命名,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch02.xhtml#type-aliases`
- 结论依据:原文的 Bytes 例用别名写签名,随后明确实际返回 Vec<u8>。
- 原始内容:The type keyword can be used like typedef in C++ to declare a new name for an existing type: