Struct Box

Source
pub struct Box<T: ?Sized, S: Storage = Global> { /* private fields */ }
Expand description

A type that owns a single T allocated in a Storage

This currently stores an extra dangling non-null pointer when using the nightly feature, so that CoerceUnsized can attach metadata to it when this Box get unsized

Box does not support T: ?Sized types when not using the nightly feature

Implementations§

Source§

impl<T, S: Storage + Default> Box<T, S>

Source

pub fn new(value: T) -> Result<Self, StorageAllocError>

Source

pub fn new_with(f: impl FnOnce() -> T) -> Result<Self, StorageAllocError>

Box::new_with_in but using Default::default for the Storage

This function has an advantage over Box::new for large objects where because the allocation is done before f is called, the stack space for the return value of f may be elided by the compiler

Source§

impl<T, S: Storage> Box<T, S>

Source

pub fn new_in(value: T, storage: S) -> Result<Self, StorageAllocError>

Allocates room for a T in storage and moves value into it

Source

pub fn new_with_in( f: impl FnOnce() -> T, storage: S, ) -> Result<Self, StorageAllocError>

Allocates room for a T in storage and constructs value into it

This function has an advantage over Box::new_in for large objects where because the allocation is done before f is called, the stack space for the return value of f may be elided by the compiler

Source

pub fn into_inner(self) -> T

Moves the T out of this Box

Source§

impl<T: ?Sized, S: Storage> Box<T, S>

Source

pub unsafe fn from_raw_parts( storage: S, handle: S::Handle, metadata: <T as Pointee>::Metadata, ) -> Self

Reconstructs a Box from a Storage, Storage::Handle, and Pointee::Metadata

The opposite of Box::into_raw_parts

§Safety
  • handle must represent a valid allocation in storage of size_of::<T>() bytes
  • metadata must be a valid pointer metadata for the T that handle represents
Source

pub fn into_raw_parts(b: Self) -> (S, S::Handle, <T as Pointee>::Metadata)

Splits the Box into its Storage, Storage::Handle, and Pointee::Metadata

The opposite of Box::from_raw_parts

Source

pub fn as_ptr(&self) -> NonNull<T>

Gets a NonNull<T> to the T stored in this Box

Source§

impl<S: Storage> Box<dyn Any, S>

Source

pub fn downcast<T: 'static>(b: Self) -> Result<Box<T, S>, Self>

Available on crate feature nightly only.

Attempts to downcast the dyn Any to a T

Source

pub unsafe fn downcast_unchecked<T: 'static>(b: Self) -> Box<T, S>

Available on crate feature nightly only.

Downcasts the dyn Any to a T, without any checks

The safe version of this function is Box::downcast

§Safety

The contained value must be of type T

Trait Implementations§

Source§

impl<T: ?Sized, S: Storage> Deref for Box<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: Storage> DerefMut for Box<T, S>

Source§

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

Mutably dereferences the value.
Source§

impl<T: ?Sized, S: Storage> Drop for Box<T, S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T, U, S> CoerceUnsized<Box<U, S>> for Box<T, S>
where T: Unsize<U> + ?Sized, U: ?Sized, S: Storage,

Available on crate feature nightly only.
Source§

impl<T, S> Send for Box<T, S>
where T: Send + ?Sized, S: Send + Storage, S::Handle: Send,

Source§

impl<T, S> Sync for Box<T, S>
where T: Sync + ?Sized, S: Sync + Storage, S::Handle: Sync,

Auto Trait Implementations§

§

impl<T, S> Freeze for Box<T, S>
where <S as Storage>::Handle: Freeze, S: Freeze, T: ?Sized,

§

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

§

impl<T, S> Unpin for Box<T, S>
where <S as Storage>::Handle: Unpin, S: Unpin, T: Unpin + ?Sized,

§

impl<T, S> UnwindSafe for Box<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.