pub async fn get_list() -> Json<Results<String>> {
let x = handle::execute("query<->blog<->column<->[*]").unwrap();
let v = x.1.get(0).unwrap();
let v = *v;
let string = TeraEntity::render("list", &Context::new()).unwrap();
let results = Results {
code: 200,
msg: "成功".to_string(),
data: string
};
Json(results)
}
error[E0507]: cannot move out of `*v` which is behind a shared reference
--> src/methods/index.rs:53:13
|
53 | let v = *v;
| ^^
| |
| move occurs because `*v` has type `HashMap<std::string::String, std::string::String>`, which does not implement the `Copy` trait
| help: consider borrowing here: `&*v`
warning: unused import: `Read`
v这个变量不能被解引用
1
共 4 条评论, 1 页
评论区
写评论不考虑clone的话可以remove,会返回有所有权的v
那就CLONE呗
--
👇
1148118271: v 那个hashMap已经是借用类型了
我有没有什么办法直接获取 v 这个对象的所有权
v 那个hashMap已经是借用类型了
我有没有什么办法直接获取 v 这个对象的所有权
编译器给的提醒已经很清楚了啦 move occurs because
*v
has typeHashMap<std::string::String, std::string::String>
, which does not implement theCopy
traithashmap 没有copy trait所以不能使用移动语义,而且编译器得建议也很清楚哦,考虑使用借用