我正在寻找有关引用和可变引用类型的复制/移动语义的文档。
下面的代码片段展示了不可变引用(& T
)实现了Copy
特性,而可变引用(&mut T
)则没有。
struct T;
fn copyable<U>(_: U) where U: Copy {}
fn main() {
let a = &T;
copyable(a); // OK
let b = &mut T;
copyable(b);
// error: the trait `core::marker::Copy` is not implemented for the type `&mut T`
}
但我找不到关于这种行为的描述。有人知道一些(非)官方文档吗?(或者是我的理解有误?)
Copy
impls的问题:https://github.com/rust-lang/rust/issues/25893 - oli_obk&mut T
不是Copy
。 - Chris Emerson