Struct alloc::boxed::Box
[−]
[src]
pub struct Box<T: ?Sized>(_);
A pointer type for heap allocation.
See the module-level documentation for more.
Methods
impl<T> Box<T>
impl<T: ?Sized> Box<T>
unsafe fn from_raw(raw: *mut T) -> Self
: may be renamed or moved out of Box scope
Constructs a box from the raw pointer.
After this function call, pointer is owned by resulting box.
In particular, it means that Box destructor calls destructor
of T and releases memory. Since the way Box allocates and
releases memory is unspecified, the only valid pointer to pass
to this function is the one taken from another Box with
Box::into_raw function.
Function is unsafe, because improper use of this function may lead to memory problems like double-free, for example if the function is called twice on the same raw pointer.
fn into_raw(b: Box<T>) -> *mut T
: may be renamed
Consumes the Box, returning the wrapped raw pointer.
After call to this function, caller is responsible for the memory
previously managed by Box, in particular caller should properly
destroy T and release memory. The proper way to do it is to
convert pointer back to Box with Box::from_raw function, because
Box does not specify, how memory is allocated.
Examples
#![feature(box_raw)] let seventeen = Box::new(17u32); let raw = Box::into_raw(seventeen); let boxed_again = unsafe { Box::from_raw(raw) };
impl Box<Any>
fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>>
Attempt to downcast the box to a concrete type.
impl Box<Any + Send>
fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any + Send>>
Attempt to downcast the box to a concrete type.