oversized_box

Struct OversizedBox

Source
pub struct OversizedBox<T: ?Sized, S> { /* private fields */ }
Expand description

A Box for T with an allocation whose size and alignment is the same as S.

Implementations§

Source§

impl<T, S> OversizedBox<T, S>

Source

pub fn new(t: T) -> Self

Allocates a new box and inserts t.

OversizedBox::<_, u64>::new(0u32);

Fails to compile if T’s size or alignment is larger than S’s.

OversizedBox::<_, u32>::new(0u64);
Source

pub fn pin(t: T) -> Pin<Self>

Allocates a new box, inserts t, and pins the box.

Source§

impl<T: ?Sized, S> OversizedBox<T, S>

Source

pub fn refill<T2>(this: Self, t: T2) -> OversizedBox<T2, S>

Drops the current contents of the box, then replaces them with t.

Returns the new box, which may have a different type from the current one.

Panics if T2’s size or alignment is larger than S’s.

Source

pub fn empty(this: Self) -> OversizedBox<(), S>

Empties the box, dropping the contents but preserving the allocation.

Source

pub fn empty_pinned(this: Pin<Self>) -> OversizedBox<(), S>

Empties a pinned box, dropping the contents but preserving the allocation.

Source

pub fn into_pin(this: Self) -> Pin<Self>

Pins the box.

Source

pub fn into_raw(this: Self) -> (NonNull<T>, PhantomData<*mut S>)

Consumes this and returns the allocation plus the phantom data specifying the allocation type.

The phantom data is returned to make coerce! work.

Source

pub unsafe fn from_raw(t: NonNull<T>, s: PhantomData<*mut S>) -> Self

Re-creates the box from the allocation plus phantom data specifying the underlying allocation type.

The phantom data is consumed to make coerce! work.

§Safety

t must have been returned from into_raw.

Trait Implementations§

Source§

impl<T: ?Sized, S> AsMut<T> for OversizedBox<T, S>

Source§

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

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T: ?Sized, S> AsRef<T> for OversizedBox<T, S>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: ?Sized, S> Deref for OversizedBox<T, S>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: ?Sized, S> DerefMut for OversizedBox<T, S>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T: ?Sized, S> Drop for OversizedBox<T, S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: ?Sized, S> From<OversizedBox<T, S>> for Pin<OversizedBox<T, S>>

Source§

fn from(this: OversizedBox<T, S>) -> Self

Converts to this type from the input type.
Source§

impl<T: ?Sized + Send, S> Send for OversizedBox<T, S>

Source§

impl<T: ?Sized + Sync, S> Sync for OversizedBox<T, S>

Source§

impl<T: ?Sized, S> Unpin for OversizedBox<T, S>

Auto Trait Implementations§

§

impl<T, S> Freeze for OversizedBox<T, S>
where T: ?Sized,

§

impl<T, S> RefUnwindSafe for OversizedBox<T, S>

§

impl<T, S> UnwindSafe for OversizedBox<T, S>

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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.