Struct tagged_pointer::TaggedPtr [−][src]
A tagged pointer: a space-efficient representation of a pointer and integer tag.
This type stores a pointer and an integer tag without taking up more space than a normal pointer (unless the fallback implementation is used; see the module documentation).
The tagged pointer conceptually holds a NonNull<T>
and a
certain number of bits of an integer tag.
Bits
should be a type-level unsigned integer from the
typenum crate. It specifies how many bits are used for the tag. The
alignment of T
must be large enough to store this many bits; see
Self::new
.
Implementations
impl<T, Bits: Unsigned> TaggedPtr<T, Bits>
[src]
pub fn new(ptr: NonNull<T>, tag: usize) -> Self
[src]
Creates a new tagged pointer. Only the lower
Bits::USIZE
bits of tag
are stored.
Panics
This method panics if the alignment of T
is less than 2 to the power
of Bits::USIZE
. This ensures that all properly
aligned pointers to T
will be aligned enough to store the specified
number of bits of the tag.
ptr
should be “dereferencable” in the sense defined by
core::ptr
. If it is not, this method or other
methods of TaggedPtr
may panic.
It is recommended that ptr
be properly aligned (i.e., aligned to at
least mem::align_of::<T>()
), but it may have a
smaller alignment. However, if its alignment is not at least
2 to the power of Bits::USIZE
, this method may
panic.
pub fn get(self) -> (NonNull<T>, usize)
[src]
Gets the pointer and tag stored by the tagged pointer. If you need
both the pointer and tag, this method may be more efficient than
calling Self::ptr
and Self::tag
separately.
Panics
If the pointer provided to Self::new
wasn’t
“dereferencable”, this method may panic.
pub fn ptr(self) -> NonNull<T>
[src]
Gets the pointer stored by the tagged pointer, without the tag.
Equivalent to self.get().0
.
Panics
If the pointer provided to Self::new
wasn’t
“dereferencable”, this method may panic.
pub fn tag(self) -> usize
[src]
Gets the tag stored by the tagged pointer. Equivalent to
self.get().1
.
Panics
If the pointer provided to Self::new
wasn’t
“dereferencable”, this method may panic.
Trait Implementations
impl<T, Bits> Clone for TaggedPtr<T, Bits>
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T, Bits> Copy for TaggedPtr<T, Bits>
[src]
impl<T, Bits: Unsigned> Debug for TaggedPtr<T, Bits>
[src]
impl<T, Bits> Eq for TaggedPtr<T, Bits>
[src]
impl<T, Bits> Hash for TaggedPtr<T, Bits>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T, Bits> Ord for TaggedPtr<T, Bits>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T, Bits> PartialEq<TaggedPtr<T, Bits>> for TaggedPtr<T, Bits>
[src]
impl<T, Bits> PartialOrd<TaggedPtr<T, Bits>> for TaggedPtr<T, Bits>
[src]
Auto Trait Implementations
impl<T, Bits> !Send for TaggedPtr<T, Bits>
impl<T, Bits> !Sync for TaggedPtr<T, Bits>
impl<T, Bits> Unpin for TaggedPtr<T, Bits>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,