pub unsafe trait Pointer: Deref {
    const BITS: u32;

    // Required methods
    fn into_ptr(self) -> NonNull<Self::Target>;
    unsafe fn from_ptr(ptr: NonNull<Self::Target>) -> Self;
}
Expand description

This describes the pointer type encapsulated by TaggedPtr and CopyTaggedPtr.

§Safety

The pointer returned from into_ptr must be a valid, pointer to <Self as Deref>::Target.

Note that if Self implements DerefMut the pointer returned from into_ptr must be valid for writes (and thus calling NonNull::as_mut on it must be safe).

The BITS constant must be correct. BITS least-significant bits, must be zero on all pointers returned from into_ptr.

For example, if the alignment of Self::Target is 2, then BITS should be 1.

Required Associated Constants§

source

const BITS: u32

Number of unused (always zero) least-significant bits in this pointer, usually related to the pointees alignment.

For example if BITS = 2, then given ptr = Self::into_ptr(..), ptr.addr() & 0b11 == 0 must be true.

Most likely the value you want to use here is the following, unless your Self::Target type is unsized (e.g., ty::List<T> in rustc) or your pointer is over/under aligned, in which case you’ll need to manually figure out what the right type to pass to bits_for is, or what the value to set here.

const BITS: u32 = bits_for::<<Self as Deref>::Target>();

Required Methods§

source

fn into_ptr(self) -> NonNull<Self::Target>

Turns this pointer into a raw, non-null pointer.

The inverse of this function is from_ptr.

This function guarantees that the least-significant Self::BITS bits are zero.

source

unsafe fn from_ptr(ptr: NonNull<Self::Target>) -> Self

Re-creates the original pointer, from a raw pointer returned by into_ptr.

§Safety

The passed ptr must be returned from into_ptr.

This acts as ptr::read::<Self>() semantically, it should not be called more than once on non-Copy Pointers.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'a, T: 'a + ?Sized + Aligned> Pointer for &'a T

source§

const BITS: u32 = _

source§

fn into_ptr(self) -> NonNull<T>

source§

unsafe fn from_ptr(ptr: NonNull<T>) -> Self

source§

impl<'a, T: 'a + ?Sized + Aligned> Pointer for &'a mut T

source§

const BITS: u32 = _

source§

fn into_ptr(self) -> NonNull<T>

source§

unsafe fn from_ptr(ptr: NonNull<T>) -> Self

source§

impl<T: ?Sized + Aligned> Pointer for Box<T>

source§

const BITS: u32 = _

source§

fn into_ptr(self) -> NonNull<T>

source§

unsafe fn from_ptr(ptr: NonNull<T>) -> Self

source§

impl<T: ?Sized + Aligned> Pointer for Arc<T>

source§

const BITS: u32 = _

source§

fn into_ptr(self) -> NonNull<T>

source§

unsafe fn from_ptr(ptr: NonNull<T>) -> Self

Implementors§

source§

impl<T: ?Sized + Aligned> Pointer for Rc<T>

source§

const BITS: u32 = _