官术网_书友最值得收藏!

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
主站蜘蛛池模板: 安达市| 中方县| 诸城市| 乌拉特前旗| 东安县| 彩票| 德江县| 政和县| 达孜县| 全南县| 雅安市| 辉南县| 龙川县| 精河县| 景德镇市| 监利县| 古交市| 文登市| 永和县| 湟源县| 沅江市| 修文县| 阿瓦提县| 柘荣县| 古丈县| 来凤县| 咸宁市| 宣汉县| 类乌齐县| 卢龙县| 游戏| 林甸县| 溧阳市| 马龙县| 镇宁| 阜城县| 吴忠市| 莎车县| 读书| 杂多县| 兴山县|