- 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.
推薦閱讀
- Vue.js設計與實現
- 深度實踐OpenStack:基于Python的OpenStack組件開發
- 數據結構和算法基礎(Java語言實現)
- .NET 3.5編程
- Python忍者秘籍
- Visual FoxPro程序設計習題集及實驗指導(第四版)
- Python深度學習:模型、方法與實現
- RealSenseTM互動開發實戰
- Building Machine Learning Systems with Python(Second Edition)
- Apache Camel Developer's Cookbook
- Qt5 C++ GUI Programming Cookbook
- GitHub入門與實踐
- 軟件工程基礎與實訓教程
- Instant Automapper
- 從零開始學Selenium自動化測試:基于Python:視頻教學版