Struct StuffedPtr

Source
pub struct StuffedPtr<T, S, B = usize>(/* private fields */)
where
    S: StuffingStrategy<B>,
    B: Backend<T>;
Expand description

A union of a pointer or some other data, bitpacked into a value with the size depending on B. It defaults to usize, meaning pointer sized, but u64 and u128 are also provided by this crate. You can also provide your own Backend implementation

The stuffing strategy is supplied as the second generic parameter S.

The first generic parameter T is the type that the pointer is pointing to.

For a usage example, view the crate level documentation.

This pointer does not drop other data, StuffedPtr::into_other can be used if that is required.

StuffedPtr implements most traits like Clone, PartialEq or Copy if the other type does.

This type is guaranteed to be #[repr(transparent)] to a B::Stored.

Implementations§

Source§

impl<T, S, B> StuffedPtr<T, S, B>
where S: StuffingStrategy<B>, B: Backend<T>,

Source

pub fn new_ptr(ptr: *mut T) -> Self

Create a new StuffedPtr from a pointer

Source

pub fn new_other(other: S::Other) -> Self

Create a new StuffPtr from other data

Source

pub fn get_ptr(&self) -> Option<*mut T>

Get the pointer data, or None if it contains other data

Source

pub unsafe fn get_ptr_unchecked(&self) -> *mut T

Get the unstuffed pointer data from the stuffed pointer, assuming that the StuffedPtr contains pointer data.

§Safety

StuffedPtr must contain pointer data and not other data

Source

pub fn into_other(self) -> Option<S::Other>

Get owned other data from this, or None if it contains pointer data

Source

pub unsafe fn into_other_unchecked(self) -> S::Other

Turn this pointer into other data.

§Safety

StuffedPtr must contain other data and not pointer

Source

pub unsafe fn get_other(&self) -> Option<S::Other>

Get other data from this, or None if it contains pointer data

§Safety

The caller must guarantee that only ever on Other exists if Other: !Copy

Source

pub unsafe fn get_other_unchecked(&self) -> S::Other

Get other data from this

§Safety

Must contain other data and not pointer data, and the caller must guarantee that only ever on Other exists if Other: !Copy

Source§

impl<T, S, B> StuffedPtr<T, S, B>
where S: StuffingStrategy<B>, S::Other: Copy, B: Backend<T>,

Extra implementations if the other type is Copy

Source

pub fn copy_other(&self) -> Option<S::Other>

Get other data from this, or None if it’s pointer data

Source

pub unsafe fn copy_other_unchecked(&self) -> S::Other

Get other data from this

§Safety

Must contain other data and not pointer data,

Trait Implementations§

Source§

impl<T, S, B> Clone for StuffedPtr<T, S, B>
where S: StuffingStrategy<B>, S::Other: Clone, B: Backend<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, S, B> Debug for StuffedPtr<T, S, B>
where S: StuffingStrategy<B>, S::Other: Debug, B: Backend<T>,

Source§

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

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

impl<T, S, B> Hash for StuffedPtr<T, S, B>
where S: StuffingStrategy<B>, S::Other: Hash, B: Backend<T>,

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T, S, B> PartialEq for StuffedPtr<T, S, B>
where S: StuffingStrategy<B>, S::Other: PartialEq, B: Backend<T>,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, S, B> Copy for StuffedPtr<T, S, B>
where S: StuffingStrategy<B>, S::Other: Copy, B: Backend<T>,

Source§

impl<T, S, B> Eq for StuffedPtr<T, S, B>
where S: StuffingStrategy<B>, S::Other: PartialEq + Eq, B: Backend<T>,

Auto Trait Implementations§

§

impl<T, S, B> Freeze for StuffedPtr<T, S, B>
where <B as Backend<T>>::Stored: Freeze,

§

impl<T, S, B> RefUnwindSafe for StuffedPtr<T, S, B>
where <B as Backend<T>>::Stored: RefUnwindSafe, S: RefUnwindSafe,

§

impl<T, S, B> Send for StuffedPtr<T, S, B>
where <B as Backend<T>>::Stored: Send, S: Send,

§

impl<T, S, B> Sync for StuffedPtr<T, S, B>
where <B as Backend<T>>::Stored: Sync, S: Sync,

§

impl<T, S, B> Unpin for StuffedPtr<T, S, B>
where <B as Backend<T>>::Stored: Unpin, S: Unpin,

§

impl<T, S, B> UnwindSafe for StuffedPtr<T, S, B>
where <B as Backend<T>>::Stored: UnwindSafe, S: 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, 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.