【发布时间】:2015-06-22 07:50:14
【问题描述】:
我有这个代码:
enum MyEnum1 {
val1,
val2
}
struct Struct1 {
field1: MyEnum1,
field2: String
}
fn fn1(a: Struct1, b: String, c: String) {
let let1 = fn2(&a.field1);
}
fn fn2(a: &MyEnum1) {
let a11 = *a; // error
let s = Struct1 { field1: a11, field2: "fdsfds".to_string() };
}
fn main() {
println!("Hello World!");
}
错误是错误:无法移出借来的内容
编译器建议我使用ref 或ref mut,我尝试使用它们,但仍然没有帮助。
fn fn2(a: &MyEnum1) {
let ref a11 = *a; // still the error
let s = Struct1 { field1: *a11, field2: "fdsfds".to_string() };
}
【问题讨论】:
-
实际上错误现在在下一行,而不是在您添加
still the error评论的那一行 -
解决办法是复制,问题是“不能搬出借来的内容”,我觉得这很重复
标签: rust