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

  • 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.

主站蜘蛛池模板: 疏勒县| 蕲春县| 东丽区| 舞阳县| 英德市| 西城区| 宜良县| 嘉禾县| 民县| 寻甸| 祥云县| 胶州市| 许昌县| 庄浪县| 太原市| 绥宁县| 岳阳县| 兰州市| 土默特左旗| 保亭| 隆尧县| 苏州市| 红原县| 巴南区| 平湖市| 江阴市| 郓城县| 包头市| 疏附县| 宣威市| 宁都县| 新平| 三门峡市| 鄂托克旗| 饶平县| 浦北县| 望江县| 家居| 大埔县| 遵化市| 曲松县|