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

    // Required methods
    fn into_usize(self) -> usize;
    unsafe fn from_usize(ptr: usize) -> Self;
    unsafe fn with_ref<R, F: FnOnce(&Self) -> R>(ptr: usize, f: F) -> R;
}
Expand description

This describes the pointer type encapsulated by TaggedPtr.

Safety

The usize returned from into_usize must be a valid, dereferenceable, pointer to <Self as Deref>::Target. Note that pointers to Pointee must be thin, even though Pointee may not be sized.

Note that the returned pointer from into_usize should be castable to &mut <Self as Deref>::Target if Pointer: DerefMut.

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

For example, if the alignment of Pointee is 2, then BITS should be 1.

Required Associated Constants§

source

const BITS: usize

Most likely the value you want to use here is the following, unless your Pointee type is unsized (e.g., ty::List<T> in rustc) in which case you’ll need to manually figure out what the right type to pass to align_of is.

ⓘ
std::mem::align_of::<<Self as Deref>::Target>().trailing_zeros() as usize;

Required Methods§

source

fn into_usize(self) -> usize

source

unsafe fn from_usize(ptr: usize) -> Self

Safety

The passed ptr must be returned from into_usize.

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

source

unsafe fn with_ref<R, F: FnOnce(&Self) -> R>(ptr: usize, f: F) -> R

This provides a reference to the Pointer itself, rather than the Deref::Target. It is used for cases where we want to call methods that may be implement differently for the Pointer than the Pointee (e.g., Rc::clone vs cloning the inner value).

Safety

The passed ptr must be returned from into_usize.

Implementations on Foreign Types§

source§

impl<T> Pointer for Arc<T>

source§

const BITS: usize = _

source§

fn into_usize(self) -> usize

source§

unsafe fn from_usize(ptr: usize) -> Self

source§

unsafe fn with_ref<R, F: FnOnce(&Self) -> R>(ptr: usize, f: F) -> R

source§

impl<T> Pointer for Box<T>

source§

const BITS: usize = _

source§

fn into_usize(self) -> usize

source§

unsafe fn from_usize(ptr: usize) -> Self

source§

unsafe fn with_ref<R, F: FnOnce(&Self) -> R>(ptr: usize, f: F) -> R

source§

impl<'a, T: 'a> Pointer for &'a T

source§

const BITS: usize = _

source§

fn into_usize(self) -> usize

source§

unsafe fn from_usize(ptr: usize) -> Self

source§

unsafe fn with_ref<R, F: FnOnce(&Self) -> R>(ptr: usize, f: F) -> R

source§

impl<'a, T: 'a> Pointer for &'a mut T

source§

const BITS: usize = _

source§

fn into_usize(self) -> usize

source§

unsafe fn from_usize(ptr: usize) -> Self

source§

unsafe fn with_ref<R, F: FnOnce(&Self) -> R>(ptr: usize, f: F) -> R

Implementors§

source§

impl<T> Pointer for Rc<T>

source§

const BITS: usize = _