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

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
主站蜘蛛池模板: 五原县| 哈尔滨市| 白朗县| 县级市| 阿瓦提县| 固阳县| 新闻| 台湾省| 长子县| 永仁县| 三台县| 平阴县| 松江区| 铁岭市| 长阳| 永城市| 普兰店市| 新邵县| 凤阳县| 霍城县| 娄底市| 承德市| 安阳市| 黑龙江省| 昭平县| 临安市| 那曲县| 基隆市| 延吉市| 会东县| 永和县| 曲阜市| 伽师县| 含山县| 昌邑市| 威信县| 新竹市| 榆林市| 临城县| 临沧市| 许昌市|