- 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.
推薦閱讀
- 數據庫系統教程(第2版)
- JavaScript Unlocked
- Python測試開發入門與實踐
- Unity Virtual Reality Projects
- Unity Shader入門精要
- Web程序設計(第二版)
- Tableau 10 Bootcamp
- MINECRAFT編程:使用Python語言玩轉我的世界
- Python函數式編程(第2版)
- Scala Functional Programming Patterns
- 貫通Tomcat開發
- 多媒體技術及應用
- Hands-On Dependency Injection in Go
- LabVIEW數據采集(第2版)
- Internet of Things with Arduino Cookbook