Trait rustc_data_structures::tagged_ptr::Pointer
source · 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§
sourceconst BITS: u32
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>();