- Rust Essentials(Second Edition)
- Ivo Balbaert
- 99字
- 2021-07-02 15:30:39
Aliasing
It can be useful sometimes to give a new, more descriptive, or shorter name to an existing type. This is done with the keyword type, as in the following example where we needed a specific (but size-limited) variable for MagicPower:
// see Chapter 2/code/alias.rs type MagicPower = u16; fn main() { let mut run: MagicPower= 7800; }
A type name starts with a capital letter, as does each word part of the name.
What happens when we change the value 7800 to 78000? The compiler detects this with the following warning:
warning: literal out of range for u16
推薦閱讀
- Mastering Visual Studio 2017
- ASP.NET Web API:Build RESTful web applications and services on the .NET framework
- Visual FoxPro程序設計教程
- 青少年美育趣味課堂:XMind思維導圖制作
- 高級C/C++編譯技術(典藏版)
- Mastering Kali Linux for Web Penetration Testing
- Expert Android Programming
- Learning Probabilistic Graphical Models in R
- Julia for Data Science
- Arduino Wearable Projects
- Python 3 Object:oriented Programming(Second Edition)
- SignalR:Real-time Application Development(Second Edition)
- 前端架構設計
- RESTful Web API Design with Node.js
- 計算機應用基礎