引用
有两种引用类型
- 共享引用:
&
- 可变引用:
&mut
它们遵循以下规则
- 引用不能比它引用的对象活得更久
- 可变引用不能被别名化
就是这样。这就是引用的整个模型。
当然,我们应该定义一下别名化是什么意思。
error[E0425]: cannot find value `aliased` in this scope
--> <rust.rs>:2:20
|
2 | println!("{}", aliased);
| ^^^^^^^ not found in this scope
error: aborting due to previous error
不幸的是,Rust 实际上并没有定义它的别名模型。🙀
在我们等待 Rust 开发者们明确其语言的语义时,让我们用下一节来讨论别名化的一般概念,以及它为什么重要。