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

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

主站蜘蛛池模板: 繁峙县| 天长市| 商都县| 化隆| 大埔县| 西华县| 清原| 文成县| 乌什县| 广昌县| 庄浪县| 江西省| 英超| 三台县| 潞城市| 泰宁县| 广元市| 三穗县| 色达县| 库尔勒市| 盘锦市| 嵊州市| 忻州市| 射阳县| 沂源县| 鄱阳县| 松溪县| 平邑县| 宜阳县| 无为县| 嘉荫县| 通辽市| 鄯善县| 景泰县| 黔江区| 方城县| 修水县| 紫云| 灵石县| 临朐县| 那曲县|