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

  • Learning Rust
  • Paul Johnson Vesa Kaihlavirta
  • 98字
  • 2021-07-02 23:07:19

The reference type

A reference is written in one of three ways: &, ref, or ref mut:

let mut var = 4; 
let ref_to_var = &var; 
let ref second_ref = var; 
let ref mut third_ref = var; 

The references are all equivalent here. Note, however, that the preceding code doesn't work as it is due to mutable reference rules. Rust allows several immutable reference to a thing, but if a mutable reference is taken, no other references may exist at the time. Therefore, the last line would not work, since there are already two active references to var.

主站蜘蛛池模板: 巴林右旗| 海阳市| 岑溪市| 桃源县| 湖州市| 牡丹江市| 黄石市| 新兴县| 安国市| 宁蒗| 宁安市| 咸丰县| 达日县| 科技| 山西省| 托里县| 巍山| 台北县| 武宣县| 江都市| 新绛县| 如东县| 泽库县| 安岳县| 临城县| 米林县| 汶川县| 钟山县| 南岸区| 蒲城县| 田阳县| 宣化县| 岑巩县| 闽清县| 绥阳县| 泊头市| 宁津县| 弥勒县| 健康| 平舆县| 乐陵市|