- 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.
推薦閱讀
- UI設計基礎培訓教程
- Mastering RabbitMQ
- JavaScript 網頁編程從入門到精通 (清華社"視頻大講堂"大系·網絡開發視頻大講堂)
- 數據結構(Java語言描述)
- 實戰Java高并發程序設計(第3版)
- Keras深度學習實戰
- C語言開發基礎教程(Dev-C++)(第2版)
- C#程序設計教程(第3版)
- LabVIEW虛擬儀器入門與測控應用100例
- Go語言入門經典
- 嵌入式C編程實戰
- Spring Boot從入門到實戰
- Mastering Machine Learning with R
- Implementing Domain:Specific Languages with Xtext and Xtend
- Scratch編程入門與算法進階(第2版)