
上QQ阅读APP看书,第一时间看更新
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