I'm looking for the document about copy/move semantics of reference and mutable reference types.
The following code snippet shows immutable references (& T
) implement the Copy
trait and mutable references (&mut T
) do not.
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`
}
But I can't find the description of this behavior. Someone know some (un)official documents? (or am I wrong?)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…