Expand description
Move references.
A move reference represents an owned value that is stored “somewhere else”. We own the value, not the storage.
A [MoveRef<'a, T>
] represents a permanent unique reference to T
for
the lifetime 'a
: it is the longest-lived possible reference to the
pointee, making it closer to a Box<T>
Like [&mut T
] but unlike Box<T>
, a MoveRef<T>
is not responsible
for destroying its storage, meaning that it is storage agnostic. The storage
might be on the stack or on the heap; some RAII value on the stack is
responsible for destroying just the storage, once the MoveRef<T>
itself
is gone.
The main mechanism for obtaining MoveRef
s is the moveit!()
macro,
which is analogous to a theoretical &move expr
operator. This macro
wraps DerefMove
, much like &mut expr
wraps DerefMut
.
Implementing DerefMove
is a delicate affair; its documentation details
exactly how it should be done.
§Drop Flags
In order to be sound, a MoveRef
must also hold a pointer to a drop flag,
which is used to detect if the MoveRef
was dropped without destruction.
In general, mem::forget
ing a MoveRef
is a very, very bad idea. In the
best case it will leak memory, but in some cases will crash the program in
order to observe safety guarantees.
Structs§
- A
MoveRef<'a, T>
represents an ownedT
whose storage location is valid but unspecified.
Traits§
- A trait for getting a pinned
MoveRef
for some pointer typeSelf
. - Moving dereference operations.