crossbeam_epoch

Trait Pointable

Source
pub trait Pointable {
    type Init;

    const ALIGN: usize;

    // Required methods
    unsafe fn init(init: Self::Init) -> usize;
    unsafe fn deref<'a>(ptr: usize) -> &'a Self;
    unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut Self;
    unsafe fn drop(ptr: usize);
}
Expand description

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 std::mem::MaybeUninit;
use crossbeam_epoch::Owned;

let o = Owned::<[MaybeUninit<i32>]>::init(10); // allocating [i32; 10]

Required Associated Constants§

Source

const ALIGN: usize

The alignment of pointer.

Required Associated Types§

Source

type Init

The type for initializers.

Required Methods§

Source

unsafe fn init(init: Self::Init) -> usize

Initializes a with the given initializer.

§Safety

The result should be a multiple of ALIGN.

Source

unsafe fn deref<'a>(ptr: usize) -> &'a Self

Dereferences the given pointer.

§Safety
Source

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut Self

Mutably dereferences the given pointer.

§Safety
Source

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer.

§Safety

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> Pointable for [MaybeUninit<T>]

Source§

const ALIGN: usize = _

Source§

type Init = usize

Source§

unsafe fn init(len: Self::Init) -> usize

Source§

unsafe fn deref<'a>(ptr: usize) -> &'a Self

Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut Self

Source§

unsafe fn drop(ptr: usize)

Implementors§

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

Source§

type Init = T