我想将一个引用元组(所有引用都是同一个结构体成员的引用)转换为元组的引用。
我尝试了各种方式来强制转换它们,但是我无法做到不克隆就完成转换。
struct Bar();
struct Foo(Bar, Bar, Bar);
fn main() {
let a: &Foo = &Foo(Bar(), Bar(), Bar());
let b: &(Bar, Bar) = &(a.0, a.1);
}
error[E0507]: cannot move out of borrowed content
--> src/main.rs:7:28
|
7 | let b: &(Bar, Bar) = &(a.0, a.1);
| ^^^ cannot move out of borrowed content
error[E0507]: cannot move out of borrowed content
--> src/main.rs:7:33
|
7 | let b: &(Bar, Bar) = &(a.0, a.1);
| ^^^ cannot move out of borrowed content
假设 a
的类型是 &Foo
,我期望 b
的类型为 &(Bar, Bar)
。