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>
impl<T, S: Storage + Default> Box<T, S>
Sourcepub fn new(value: T) -> Result<Self, StorageAllocError>
pub fn new(value: T) -> Result<Self, StorageAllocError>
Box::new_in but using Default::default for the Storage
Sourcepub fn new_with(f: impl FnOnce() -> T) -> Result<Self, StorageAllocError>
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>
impl<T, S: Storage> Box<T, S>
Sourcepub fn new_in(value: T, storage: S) -> Result<Self, StorageAllocError>
pub fn new_in(value: T, storage: S) -> Result<Self, StorageAllocError>
Allocates room for a T in storage and moves value into it
Sourcepub fn new_with_in(
f: impl FnOnce() -> T,
storage: S,
) -> Result<Self, StorageAllocError>
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
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Moves the T out of this Box
Source§impl<T: ?Sized, S: Storage> Box<T, S>
impl<T: ?Sized, S: Storage> Box<T, S>
Sourcepub unsafe fn from_raw_parts(
storage: S,
handle: S::Handle,
metadata: <T as Pointee>::Metadata,
) -> Self
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
handlemust represent a valid allocation instorageofsize_of::<T>()bytesmetadatamust be a valid pointer metadata for theTthathandlerepresents
Sourcepub fn into_raw_parts(b: Self) -> (S, S::Handle, <T as Pointee>::Metadata)
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
Sourcepub fn as_ptr(&self) -> NonNull<T>
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>
impl<S: Storage> Box<dyn Any, S>
Sourcepub fn downcast<T: 'static>(b: Self) -> Result<Box<T, S>, Self>
Available on crate feature nightly only.
pub fn downcast<T: 'static>(b: Self) -> Result<Box<T, S>, Self>
nightly only.Attempts to downcast the dyn Any to a T
Sourcepub unsafe fn downcast_unchecked<T: 'static>(b: Self) -> Box<T, S>
Available on crate feature nightly only.
pub unsafe fn downcast_unchecked<T: 'static>(b: Self) -> Box<T, S>
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§
impl<T, U, S> CoerceUnsized<Box<U, S>> for Box<T, S>
nightly only.