pub struct Handle<T> { /* private fields */ }
Expand description
A handle to a heap object.
Handle
may be cheaply copied as is necessary to serve your needs. It’s even legal for it
to outlive the object it refers to, provided it is no longer used to access it afterwards.
Implementations
sourceimpl<T> Handle<T>
impl<T> Handle<T>
sourcepub unsafe fn get_unchecked(&self) -> &T
pub unsafe fn get_unchecked(&self) -> &T
Get a reference to the object this handle refers to without checking any invariants.
You almost certainly do not want to use this function: consider Heap::get
or
Heap::get_unchecked
instead; both are safer than this function.
The following invariants must be upheld by you, the responsible programmer:
- The object must still be alive (i.e: accessible from the heap it was created on)
- The object must not be mutably accessible elsewhere (i.e: has any live references to
it) by any other part of the program. Immutable references are permitted. Other handles
(i.e:
Handle
orRooted
are also permitted, provided they are not in use. - That a garbage collection of the heap this object belongs to does not occur while the reference this function creates is live.
If any of these invariants are not upheld, undefined behaviour will result when using this function. If all are upheld, this function provides zero-cost access to underlying object.
sourcepub unsafe fn get_mut_unchecked(&self) -> &mut T
pub unsafe fn get_mut_unchecked(&self) -> &mut T
Get a mutable reference to the object this handle refers to without checking any invariants.
You almost certainly do not want to use this function: consider [Heap::mutate
] or
[Heap::mutate_unchecked
] instead; both are safer than this function.
The following invariants must be upheld by you, the responsible programmer:
- The object must still be alive (i.e: accessible from the heap it was created on)
- The object must not be accessible elsewhere (i.e: has any live references to it),
either mutably or immutably, by any other part of the program. Other handles (i.e:
Handle
orRooted
are permitted, provided they are not in use. - That a garbage collection of the heap this object belongs to does not occur while the reference this function creates is live.
If any of these invariants are not upheld, undefined behaviour will result when using this function. If all are upheld, this function provides zero-cost access to underlying object.