Struct PointerValuePair

Source
pub struct PointerValuePair<T> { /* private fields */ }
Expand description

A pair consisting of a raw pointer (*const T) and an integer value, packed so that it takes the size of a pointer.

It is implemented by packing the integer value in the low bits of the pointer that are known to be zero because of alignment constraints.

The size of the value that can be stored alongside the pointer is 3 bits for most types, but ultimately depends on the minimum alignment of T: for example, if mem::align_of::<T>() == 16 then 4 bits are available to store the value.

§Notes

Pointers to zero-sized types do not have enough space to store any value, so it must be zero.

Implementations§

Source§

impl<T> PointerValuePair<T>

Source

pub fn new(ptr: *const T, value: usize) -> PointerValuePair<T>

Creates a new PointerValuePair from the given raw pointer and extra bits.

§Panics

Panics if the pointer type *const T does not have enough available low bits to store the value.

Source

pub const fn available_bits() -> u32

Returns the number of bits available to store the value.

Source

pub const fn max_value() -> usize

Returns the maximum (inclusive) integer value that can be stored in the pointer.

Source

pub const fn ptr(self) -> *const T

Returns the pointer.

Source

pub const fn value(self) -> usize

Returns the value stored alongside the pointer.

Trait Implementations§

Source§

impl<T> Clone for PointerValuePair<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for PointerValuePair<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Copy for PointerValuePair<T>

Auto Trait Implementations§

§

impl<T> Freeze for PointerValuePair<T>

§

impl<T> RefUnwindSafe for PointerValuePair<T>
where T: RefUnwindSafe,

§

impl<T> Send for PointerValuePair<T>
where T: Send,

§

impl<T> Sync for PointerValuePair<T>
where T: Sync,

§

impl<T> Unpin for PointerValuePair<T>
where T: Unpin,

§

impl<T> UnwindSafe for PointerValuePair<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.