Trait Pointable
trait Pointable
Types that are pointed to by a single word.
In concurrent programming, it is necessary to represent an object within a word because atomic operations (e.g., reads, writes, read-modify-writes) support only single words. This trait qualifies such types that are pointed to by a single word.
The trait generalizes Box<T> for a sized type T. In a box, an object of type T is
allocated in heap and it is owned by a single-word pointer. This trait is also implemented for
[MaybeUninit<T>] by storing its size along with its elements and pointing to the pair of array
size and elements.
Pointers to Pointable types can be stored in Atomic, Owned, and Shared. In
particular, Crossbeam supports dynamically sized slices as follows.
use MaybeUninit;
use Owned;
let o = init; // allocating [i32; 10]
Associated Types
type InitThe type for initializers.
Required Methods
unsafe fn init(init: <Self as >::Init) -> usizeInitializes a with the given initializer.
Safety
The result should be a multiple of
ALIGN.unsafe fn deref<'a>(ptr: usize) -> &'a SelfDereferences the given pointer.
Safety
- The given
ptrshould have been initialized withPointable::init. ptrshould not have yet been dropped byPointable::drop.ptrshould not be mutably dereferenced byPointable::deref_mutconcurrently.
- The given
unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut SelfMutably dereferences the given pointer.
Safety
- The given
ptrshould have been initialized withPointable::init. ptrshould not have yet been dropped byPointable::drop.ptrshould not be dereferenced byPointable::dereforPointable::deref_mutconcurrently.
- The given
unsafe fn drop(ptr: usize)Drops the object pointed to by the given pointer.
Safety
- The given
ptrshould have been initialized withPointable::init. ptrshould not have yet been dropped byPointable::drop.ptrshould not be dereferenced byPointable::dereforPointable::deref_mutconcurrently.
- The given
Implementors
impl<T> Pointable for Guardimpl<T> Pointable for Timpl<T> Pointable for Collectorimpl<T> Pointable for Shared<'g, T>impl<T> Pointable for LocalHandleimpl<T> Pointable for Atomic<T>impl<T> Pointable for CompareExchangeError<'g, T, P>impl<T> Pointable for [MaybeUninit<T>]impl<T> Pointable for Owned<T>