【发布时间】:2018-01-21 03:49:42
【问题描述】:
以下代码:
use std::rc::Rc;
fn main() {
let s = Rc::new(String::from("Hello"));
let o: &String = *s;
}
给我这个错误:
= note: expected type `&std::string::String`
found type `std::string::String`
我预计*s 会提供某种参考,因为deref 签名是fn deref(&self) -> &T。
让我感到困惑的一件事是,如果我将 let o 行更改为:
let o: String = *s;
我现在收到cannot move out of borrowed content 的错误。
所以我有两个相关的问题
- 为什么 Rc 值的
*s不返回引用? - 我知道引用不能移动,
*s是借用而不是引用?我以为这些词的意思是一样的?
【问题讨论】:
标签: rust